Skip to content

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 ​

FieldRequiredDefaultWhat it does
Use ParamNooffOn: 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)Noempty listThe fixed list to loop over. Only used when Use Param is off.

Outputs ​

HandleWhen 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]" }]
FieldValue
Use Paramon

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.

Released under the Apache License 2.0. Enterprise features are under the Fluxify Enterprise Edition License.