While Loop
while_loop · Nodes · Control
Repeats child workflow nodes while a condition remains true.
While Loop#
Executes body nodes until the body returns null. Use it when the number of iterations is unknown and each iteration computes the next input.
How It Works#
The first iteration receives the node input. The body returns either:
- any non-null value to continue
nullto stop
Each non-null returned value is appended to output and becomes the next iteration input. Iterations are strictly sequential.
Configuration#
max_iterations (required): Maximum body executions before the node fails if the body never returns null. Must be at least 1.
This is a safety cap for pagination and polling workflows.
Inputs & Outputs#
Input: input (required) - Initial state for the first iteration.
Outputs:
- output: Array of all non-null body results.
- loop: Current iteration input. Connect this to the loop body entry node.
After completion, loop emits null so the body path does not run again.
Stop Semantics#
Only null stops the loop.
- The final
nullis not included inoutput. falsecontinues because it is non-null.- Strings, objects, arrays, numbers,
true, andfalseall continue. - Reaching
max_iterationswithoutnullfails the node.
Pagination Example#
Initial input:
{
"cursor": null,
"items": []
}
Body logic:
- Fetch a page using
input.cursor. - Append returned items to state.
- If another page exists, return the next state:
{
"cursor": "next-cursor",
"items": ["accumulated", "items"]
}
- If there is no next page, return
null.
The While Loop output is an array of all non-null intermediate states. Read the last item for final accumulated state, or perform side effects in the body and use the output as an audit trail.
Tips#
- Connect the
loopoutput to at least one body node. - Pick a conservative
max_iterationsfor the external system. - Branches that return
nullcan stop the loop. - Use Loop for known arrays and Constant Loop for fixed counts.
Skipping an Iteration#
A body that returns skip(reason) stops the loop, and the skip is not collected.
Unlike a counted loop, each iteration here is fed the previous iteration's value, so a body that declined to produce one leaves nothing to continue from. Use skip(reason) when the loop should end without contributing a final item; return null for the ordinary stop.
Inputs
inputRequired
Outputs
outputloop
Configuration
| Field | Type | Required | Description |
|---|---|---|---|
max_iterations | integer | Yes | Maximum iterations before the loop fails if the body never returns null |
base_config | record | No | Shared node configuration. failure_mode decides what a failure of this node does to the workflow; leave it at the default stop unless the workflow handles the failure itself on the node's error output (route_to_error) or the node is a rare emergency kill switch (stop_workflow). |