Skip to main content

For Each Loop

For Each is how a flow repeats work over a list. It sits in the Programming section of the node palette.

The For Each node

One input, two outputs

That second output is the whole idea, and it is what people get wrong first.

PortFires
Top outputOnce per item, carrying that item
Bottom outputOnce, after the last item — the loop is finished

So the top port is the body of the loop and the bottom port is what happens afterwards.

Configuring it

For Each properties

PropertyWhat it takes
Loop through objectThe array to iterate. Usually a message field such as table.rows
Current ItemWhere to put the item on each pass — read this in the loop body
IndexWhere to put the zero-based position, if you need it

Everything else on the panel is common to all nodes: name, colour, delays, and Continue On Error.

Closing the loop

A For Each does not loop by itself. After the body has processed an item, the flow has to come back to the For Each node, or the loop runs exactly once and stops.

Here is a real example — the SSL Watch template, which reads a list of domains from a spreadsheet and checks each one's certificate:

A For Each loop, closed with Go To

Follow the wires and the shape is clear. Get Range produces the rows, For Each takes them, and the body — SSL, Set Cell Coord, two Set Cell Value nodes — does the work for one domain. Then Go To Next Domain jumps back to the Next Domain label, which is wired into For Each's input. The bottom output goes to Stop.

Two ways to make that return trip:

Wire it back directly. Connect the last node of the body to the For Each node's input. Fine for a short body; the wire crosses the whole loop and gets hard to follow as the body grows.

Use a Go To and a Label, as above. A Label node sits at the loop's entrance, wired into For Each; a Go To at the end of the body targets that label. No long wire, and the intent is named. See Go to Label.

Get this one right

If the loop body never returns to For Each, the flow processes the first item and then stops — no error, no warning. A loop that "only ran once" is almost always a missing return path.

See also