For Each Loop
The For Each Loop block takes a list and runs a chain of blocks once for each item in it, from the first to the last. Each round, the chain receives the current item.
When to use it
- Do the same thing for every item: send an email to each user, insert each order line, call an API for each id.
- Work through the list that a previous block returned, like the rows from DB Get All.
- Don't use it to only count rounds. Use For Loop for "run 10 times".
- Don't use it just to change every item. Transformer or Array Operations do that without a loop.
Inputs
| Field | Required | Default | What it does |
|---|---|---|---|
| Use Param | No | off | On: loop over the previous block's output, which must be a list. Off: loop over the items you type in the Data tab. |
| Array Items (Data tab) | No | empty list | The fixed list to loop over. Only used when Use Param is off. |
Outputs
| Handle | When it is used |
|---|---|
| Body (top) | Connect the first block of the chain to repeat. It runs once per item and receives that item as input. |
| Next (right) | Connect the block to run after the last item. |
The loop itself returns nothing. The block connected to Next receives an empty input, not the results of the rounds. To keep results, save them in a variable with Set Variable inside the loop.
Example
DB Get All returned these users:
json
[{ "id": 1, "email": "[email protected]" }, { "id": 2, "email": "[email protected]" }]| Field | Value |
|---|---|
| Use Param | on |
The Body chain runs twice. The first time input is { "id": 1, "email": "[email protected]" }, the second time it is { "id": 2, "email": "[email protected]" }. Put an HTTP Request in the chain to send each user a message.
How it behaves
- Items run one at a time, in order. Item two starts only when item one is done.
- An empty list is fine. The chain never runs and the flow goes straight to Next.
- Use Param needs a list. With no output at all, the block fails. An object is skipped without any error, and text is read one letter at a time, so check that you really have a list.
- An error stops the loop. If a block in the chain fails, the remaining items are skipped and the Error Handler runs.
- A Response ends everything. If the chain reaches a Response block, the whole route ends with that response.
- Shared variables. Every round sees and changes the same variables.
Related blocks
- For Loop: repeat a set number of times.
- Set Variable: collect results across rounds.
- Array Operations: change or filter a list without looping.
- Orchestrator: run different chains at the same time.
