Skip to main content

Loop Node

Run a sub-workflow multiple times. This node provides a way to iterate and sequentially run a sub-workflow consisting of 1 or more nodes.

Output of the Loop node is the concatenated output of all iterations of the sub-workflow.

Handles

The Loop node has four handles — two on the left side and two on the right side. Unlike most nodes, the Loop node does not use the standard input/output handles. Instead, it uses a dedicated set of handles to define both the main workflow flow and the loop body.

Left Side

HandleTypeDescription
inputTargetReceives data from the preceding node in the main workflow. Connect the previous node's output to this handle.
startSourceConnects to the first node of the loop body (sub-workflow). This is where each iteration begins.

Right Side

HandleTypeDescription
endTargetReceives the result of each iteration. Connect the last node of the loop body back to this handle.
outputSourceSends the concatenated output of all iterations to the next node in the main workflow.

Connecting the Loop Node

  1. Main workflow into the loop: Connect the preceding node to the input handle (left).
  2. Loop body start: Connect the start handle (left) to the first node of your sub-workflow.
  3. Loop body end: Connect the last node of your sub-workflow to the end handle (right).
  4. Main workflow out of the loop: Connect the output handle (right) to the next node in the main workflow.
First Loop Body Node ◀──  │ Start      End │  ◀── Last Loop Body Node
│ │
Previous Node ──▶ │ Input Output │ ──▶ Next Node

Parameters

initialization

JavaScript expression that returns an object. Evaluated once before the first iteration to define the loop's state variables.

Available variables:

VariableDescription
inputThe data received by the loop node from the preceding node in the main workflow.

condition

JavaScript expression evaluated before each iteration. If it evaluates to a truthy value, the sub-workflow runs. If falsy, the loop ends.

Available variables:

VariableDescription
inputThe data received by the loop node from the preceding node.
indexThe current iteration index (0-based).
outputThe output of the last iteration's terminal node (the node connected to the end handle). Not available on the first check.
state variablesAll variables defined in initialization are available directly by name (e.g. i, shouldContinue).

update

JavaScript expression evaluated after each iteration to update the loop's state variables. Must return an object with the same shape as initialization.

Available variables:

VariableDescription
inputThe data received by the loop node from the preceding node.
indexThe current iteration index (already incremented, i.e. the upcoming iteration number).
outputThe output of the terminal node from the iteration that just completed.
state variablesAll current state variables are available directly by name.

Sub-workflow Input

The first node of the loop body (connected to the start handle) receives a loop object as its input with the following properties:

PropertyDescription
loop.inputThe data received by the loop node from the preceding node.
loop.indexThe current iteration index (0-based).
loop.stateAn object containing all state variables defined in initialization (with their current values).

Loop Output

The overall output of the loop node is an array. Each element corresponds to one iteration and has the following shape:

PropertyDescription
inputThe original input to the loop node.
indexThe iteration index.
stateThe state variables at the time of that iteration.
outputThe output of the terminal node (connected to the end handle) for that iteration.

Limits

The loop node allows a maximum of 1000 iterations. If the condition does not become falsy within 1000 iterations, the node will fail.

Examples

Basic Loop with fixed number of iterations

Initialization

{
i: 0;
}

Condition

i < 10;

Update

{
i: i + 1;
}

Loop until a condition is met

This pattern is useful when you don't know the number of iterations in advance. For example, when retrieving items from a paginated data source.

Initialization

{
shouldContinue: true;
}

This condition makes sure loop runs at least once.

Condition

shouldContinue;

Update

{
shouldContinue: output.shouldContinue;
}

Update the `shouldContinue` variable with the output of the sub-workflow. Output of the sub-workflow is output data from node connected to the end handle of the loop node.