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. First node of the sub-workflow must be connected to the Start handle of the loop node. Last node of the sub-workflow must be connected to the End handle of the loop node.
Output of the Loop node is concatenated output of all iterations of the sub-workflow.
Parameters
initialization
The code to execute before the first iteration of the sub-workflow.
condition
Expression to evaluate before each iteration of the sub-workflow. If the expression evaluates to `true`, the sub-workflow will be run. If the expression evaluates to `false`, the loop will end.
update
This expression is evaluated to update the variables defined in `initialization`.
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.