Loop
The Loop node repeats the steps inside it, for each item in a list, while a condition is true, or a set number of times.
Screenshot placeholder
The palette describes it as "Iterate over items".
When to use it
Use it when the same work must happen many times. For example, send a message to every contact in a list.
Settings
| Field | What it does | Notes |
|---|---|---|
| Loop mode | How the loop decides to repeat | For each (iterate over list) (default), While (condition-based) or Repeat N times |
| Iterator expression | An expression that returns the list | Only for For each. Placeholder {{ output.items }} |
| While condition | The loop continues while this is true | Only for While. Placeholder {{ output.has_more }} |
| Repeat count | How many times to run | Only for Repeat N times. Default 5, range 1 to 1000 |
| Loop variable name | The name that holds the current item | Default item |
| Max iterations (safety cap) | An upper limit on repeats | Default 100, range 1 to 10000 |
| Output key | The name the results are stored under | Default loop_results |
| Collect all iteration results | Gathers the result of every pass | On by default |
Inputs and outputs
| Handle | Where | Purpose |
|---|---|---|
| Input | Top | The step that comes before |
| loop-body (labelled "each") | Right | Connect the steps to repeat here |
| done | Bottom | The path followed after the loop has finished |
The node card shows the loop variable and the max iterations.
Example
This is an illustrative example. You want to process a list of invoices.
- Set Loop mode to For each (iterate over list).
- Set Iterator expression to
{{ output.items }}. - Connect the each output to the steps that handle one invoice, using the
itemvariable. - Connect the done output to the step that runs once everything is processed.
Tips
- Keep Max iterations (safety cap) at a sensible value so a mistake cannot make the loop run for a very long time.
- Turn off Collect all iteration results if you do not need the output, so less data is kept.
- A While loop needs something inside it to eventually make the condition false.