While
Controlled node
Overview
The While node creates a conditional loop that repeatedly executes a workflow branch while a specified condition remains true. It reads a variable value on each iteration and compares it against a target value using a selected comparison operator. When the condition becomes false, the loop exits and execution continues.
This node is useful for polling operations, retry logic, counting loops, or any scenario where you need to repeat actions until a specific state is reached.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| run | Event | Triggers the node to evaluate the condition and either continue the loop or exit. | - |
| variableName | Text | The name or path of the variable to monitor (e.g., counter or {{status}}). Supports Handlebars templating to reference dynamic values. | - |
| [Dynamic] | Data | Additional inputs are dynamically created based on Handlebars variables referenced in the variableName field. | - |
Outputs
| Output | Type | Description |
|---|---|---|
| loop | Event | Fires when the comparison condition evaluates to true, signaling the loop body to execute again. |
| index | Number | The current iteration index (0-based) of the loop. |
| finished | Event | Fires when the comparison condition evaluates to false, indicating the loop has completed. |
Runtime Behavior and Defaults
The While node evaluates the following properties on each iteration:
| Property | Default | Description |
|---|---|---|
| operation | == | The comparison operator to use. Options: <, <=, ==, !=, >=, >. |
| breakValue | null | The target value to compare against the variable. |
Execution Flow:
- On the run event, the node reads the value specified by variableName from the variable store (checking local scope first, then global workflow scope).
- It compares this value against breakValue using the selected operation.
- If the comparison returns true, the node:
- Outputs the current index (iteration count)
- Fires the loop event
- Schedules another iteration (
repeat = true)
- If the comparison returns false, the node:
- Fires the finished event
- Ends the loop (
repeat = false)
Safety Limits:
The node includes protection against infinite loops. If the iteration count exceeds the maximum loop limit (typically 10,000), the node throws a LoopCountExceeded error and stops execution.
Example Usage
Basic Counter Loop:
- Create a SetVariable node to initialize a variable (e.g.,
counter=0). - Connect it to the While node's run input.
- Configure the While node properties:
- variableName:
counter - operation:
< - breakValue:
5
- variableName:
- Connect the loop output to your processing logic.
- Connect the processing logic to another SetVariable node that increments
counterby 1. - Connect that back to the While node's run input to form the loop.
- Connect the finished output to the next step in your workflow.
In this setup, the loop executes 5 times (indices 0-4) and fires finished when counter equals 5.
Polling Pattern:
- Set variableName to
{{apiResponse.status}} - Set operation to
!= - Set breakValue to
"completed" - Connect the loop output to a delay node, then to your API request, then back to the While node.
The loop continues polling until the status equals "completed", at which point finished fires and the workflow proceeds.
The While node checks for variables in the local scope first (variables set within the current sub-workflow), then falls back to the global workflow scope. This allows for encapsulated loop counters that don't pollute the global namespace.