> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wordware.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Loop

> Make things happen, and then make them happen again

## What does it do?

Loops let you conditionally repeat parts of your WordApp. You can use them to create complex interactions, like asking
the user for input until they give you the right answer, or generating content until it meets a certain criteria.

Loops are a powerful tool for creating dynamic, interactive WordApps. They let you build complex logic into your WordApp,
and can help you create more engaging and useful experiences. They also let you take advantage of the full power of AI,
by allowing you to iterate on the content it generates. This pattern lives at the core of every agent.

We've got some examples of how to make the most of loops in our recipes, specifically the [chatbot](/recipes/chatbots)
recipe.

<img src="https://mintcdn.com/wordware/GaAvACBL43qOk0NE/images/loops/Loops_where_they_live.png?fit=max&auto=format&n=GaAvACBL43qOk0NE&q=85&s=032e586ca35b43966bb606383f1c9392" alt="Loops Where They Live Pn" width="2406" height="1110" data-path="images/loops/Loops_where_they_live.png" />

## How do I use it?

A loop has two parts, a condition and an action. The condition determines how long to repeat the action, and the action
is what you want to repeat.

To create a loop, type `/loop` in the editor, and hit `Enter`. You'll be prompted to fill in a name and the condition
and action for the loop.

<img src="https://mintcdn.com/wordware/GaAvACBL43qOk0NE/images/loops/loop_attributes_editor.png?fit=max&auto=format&n=GaAvACBL43qOk0NE&q=85&s=f7da24eb7490ecd0bc701bdfd58d22df" alt="Loop Attributes Editor Pn" width="1196" height="1526" data-path="images/loops/loop_attributes_editor.png" />

### Options

A number of options appear in the attributes editor when you create a loop. Here's what they mean:

#### Label

The name of the loop. You'll need this later if you want to [@mention](/nodes/mention) the output of the loop.

As with a generation, this can be edited in the attributes editor:

<img src="https://mintcdn.com/wordware/GaAvACBL43qOk0NE/images/loops/loop_name_attributes.png?fit=max&auto=format&n=GaAvACBL43qOk0NE&q=85&s=fa91de960b69633a145df821d5048c6e" alt="Loop Name Attributes Pn" width="760" height="588" data-path="images/loops/loop_name_attributes.png" />

Or in the main editor:

<img src="https://mintcdn.com/wordware/GaAvACBL43qOk0NE/images/loops/loop_name_editor.png?fit=max&auto=format&n=GaAvACBL43qOk0NE&q=85&s=ed51d1882022ba31d674687ae3e30c4b" alt="Loop Name Editor Pn" width="1296" height="404" data-path="images/loops/loop_name_editor.png" />

#### Loop Type

There are three types of condition you can use to determine when to stop the loop:

<img src="https://mintcdn.com/wordware/GaAvACBL43qOk0NE/images/loops/loop_type.png?fit=max&auto=format&n=GaAvACBL43qOk0NE&q=85&s=12b894fc50e95846760d4fa5d950a3c7" alt="Loop Type Pn" width="1188" height="614" data-path="images/loops/loop_type.png" />

| Condition type | How it works                                                                               |
| -------------- | ------------------------------------------------------------------------------------------ |
| Count          | Stops after a fixed number of iterations                                                   |
| List           | Loops once for every element in a list, giving the action each such element, one at a time |
| Expression     | Choose a condition when the loop should stop repeating, e.g. `@user_input` `=` `"done"`    |

### Outputs

Loops produce a list-type output, containing all the outputs produced from the action of the loop.
