FlowsGuide

Loops

A Loop node runs the steps inside it once per item: once per element of a list, once per row a query returned, or — in While mode — until a stop condition is true. Inside the loop, steps read the current element as nodes.<loop>.item; after it, the next step reads every iteration’s result, in the order of the input list, as nodes.<loop>.output.

What you will learn
  • Point a loop at a list, an expression or a SQL step’s rows
  • Read the current element, its fields and its position in the body
  • Choose Sequential, Parallel (with how many at once) or While
  • Stop a loop early, and read a loop run iteration by iteration

How a loop runs

On the canvas a loop is a frame: the loop node on top, its body inside, an end cap at the bottom. When the run reaches it, the loop works out its list, then walks the body once per element — each iteration on its own copy of the state, so two iterations running at the same time never overwrite each other’s outputs. When every iteration is done, the flow continues under the cap.

A SQL step feeds a loop that sends one e-mail per row; the counter climbs as iterations finish.

The loop’s output, nodes.<loop>.output, is a list with one entry per iteration: the output of the body’s last step in that iteration. Results keep the order of the input list, whichever iteration finishes first.

Choose what to loop over

  1. Add the loop

    Click a + and pick Loop (For each item). The frame arrives empty; its inner + adds steps to the body.

  2. Set its Items

    In the middle of the loop’s sheet, For each item in is one expression that gives a list: a literal such as [3, 1, 2], a read such as nodes.flow_inputs.customers, or JavaScript that computes one.

  3. Fill the body

    Add the steps to repeat inside the frame and set their inputs from the current element (next section).

Pointed at a SQL step’s output, nodes.<sql step>.output, the loop goes through the query’s rows on its own, and .output.rows reads the same list. An expression can shape the list first: nodes.fetch_orders.output.orders.filter((o) => o.total > 0).

Using the item inside the body

A step in the body reads the current iteration through the loop’s own name. For a loop named each_order:

ExpressionReads
nodes.each_order.itemThe whole current element.
nodes.each_order.item.emailA field of it: a column, for a SQL row.
nodes.each_order.item["First Name"]A field whose name has spaces or symbols.
nodes.each_order.indexThe position, from 0.
nodes.each_order.iterationThe position, from 1: .index + 1, the number the run view shows.
greet_row.py
def main(email: str, first_name: str, position: int = 0):
    return {"to": email, "greeting": f"Hi {first_name}!", "position": position}

With email set to nodes.each_order.item.email, first_name to nodes.each_order.item["First Name"] and position to nodes.each_order.index, the step runs once per row. A row that lacks a field is data, not a mistake: that input reaches the step as null, and the parameter’s default does not apply. Write nodes.each_order.item.email ?? "none" when you want a fallback.

These three exist only inside the loop’s body: anywhere else the field says so (binding_loop_scope). After the loop, only nodes.each_order.output exists, and a step inside the body cannot be read from outside (binding_outside_group).

Nested loops

In a loop inside a loop, each loop keeps its own name, so the inner body reads both: nodes.each_customer.item.name from the outer loop and nodes.each_order.item.total from the inner one. The picker lists the values of every loop around the field.

Sequential, parallel or while

The loop’s Execution setting decides how iterations are scheduled:

  • Sequential (default) — one iteration at a time, in order. Use it when each item depends on the previous one, or when a service must not be called twice at once.
  • Parallel — up to At once iterations run together, at most 20 (Capped at 20 iterations at once.). They run in waves; results still land in input order.
  • While — no list: the steps repeat in passes (nodes.<loop>.item = 0, 1, 2…) until a condition says stop, At most 100 times by default (up to 1,000). See While loops below.

Stop the loop when

Stop the loop when is an optional expression checked after each iteration, in index order, with result (that iteration’s output) and the loop’s own .item and .index. The first time it is true the loop ends there, and its output keeps the iterations up to and including that one. In a parallel loop, iterations already started alongside it (at most the loop’s concurrency minus one) may have run; their results are dropped, so the output never depends on how many ran at once.

JavaScriptstop-when.js
result.found === true          // stop at the first match
nodes.each_order.index >= 9    // at most ten iterations

When an iteration fails

A failing iteration fails the loop: the iterations already running finish, no new wave starts, and the failure reported is the first by index — the same one every time, however the timing fell. A step with continue on error in its run settings lets the other iterations carry on instead.

While loops: pages, cursors and waiting

A While loop runs its steps in passes. Each pass can read what the pass before it returned as nodes.<loop>.previous (empty on the first pass), which is all you need to ask an API for the next page.

  • Run a pass while is checked before each pass, the first one too. False before the first pass means no pass runs.
  • Stop after a pass when is checked after each pass, with result (that pass’s result) and carry.
  • Fill at least one of the two. At the limit decides what reaching At most means: Fail the step (the default, loop_max_iterations) or Stop and keep what it has.
  • Carried state keeps a value from pass to pass: Start with runs once, After each pass computes the next one from result and carry. The steps read it as nodes.<loop>.carry, and the run shows it in and out for every pass.
  • The loop gives every pass’s result (a list), only the last one (for waiting on a job), or One list joined: the lists found at Items at in every pass, joined into one.
  • Wait between passes pauses up to 60 seconds before the next pass. The wait counts in the flow’s time limit; a wait that would pass it fails at once.

Every page of a search (search_after)

An HTTP step inside the loop asks for 10,000 hits after the last one of the previous pass. The loop stops when a page comes back short and joins every page’s hits into one list.

JavaScriptrequest body
({
  size: 10000,
  ...(nodes.brand_pages.previous
    ? { search_after: nodes.brand_pages.previous.body.hits.hits.at(-1).sort }
    : {}),
})
JavaScriptstop after a pass when
result.body.hits.hits.length < 10000
// The loop gives: One list joined · Items at: body.hits.hits

A cursor API

JavaScriptrun a pass while
nodes.pages.previous === null || nodes.pages.previous.body.nextCursor
JavaScriptquery: cursor
nodes.pages.previous?.body.nextCursor ?? ""

Waiting for a job to finish

Set Wait between passes to a few seconds and The loop gives to Only the last: the step after the loop reads the job’s final answer.

JavaScriptstop after a pass when
result.body.status === 'done' || result.body.status === 'failed'

Reading a loop run

The loop header tells its own story while it runs and after: 120 items · 5 at a time, 37 of 120 done, then the outcome counts — 118 ok, 2 failed, skipped, from cache. When something failed, a pill jumps between failures: Next failure · #41 · 1 of 2.

  • The arrows and the picker on the loop node choose which iteration the canvas shows — every step in the body repaints with that iteration’s status, inputs and output.
  • The loop’s Iterations tab is a table — Item, Status, Duration — with a Failed only filter. A long loop loads its rows as you scroll (Loading this iteration…).
  • The run’s Timeline draws one lane per iteration running at the same time, so a parallel loop shows its waves.

Limits and rules

  • Parallel loops run at most 20 iterations at once; a higher value is capped.
  • While loops repeat at most 1,000 times (100 by default), need Run a pass while or Stop after a pass when, and fail at the limit unless set to stop there. They wait at most 60 seconds between passes.
  • A loop’s list must be a list: an object or a number is marked in the field when that can be proved (binding_wrong_type), and otherwise fails the loop when it runs.
  • A loop over a result too large to pass between steps reads its rows from storage, page by page (large results).