While node
The While node allows executing a sequence of nodes as long as a condition is true. It allows repeating an operation until a condition is met, waiting for a state to change, implementing conditional loops or polling until a result is obtained.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| Condition | JavaScript (boolean) | ✅ | — | Run JavaScript code that returns a boolean to determine whether we stay in the loop or exit it. |
| Loop mode | While / Do while | ✅ | — | Behavior choice: While or Do while. |
Condition
Run JavaScript code that returns a boolean:
true: the loop continuesfalse: the loop stops
Examples:
context.data.status !== "completed"
context.variables.attempts < 5
context.lastResponse.data === undefined
Loop mode
The toggle allows choosing between two modes:
- While: checks the condition before executing the loop code
- Do while: executes the code at least once, then checks the condition
Execution
- The condition is evaluated
- According to the chosen mode:
- While: executes the loop if the condition is
true - Do while: first executes the loop, then checks the condition
- While: executes the loop if the condition is
- The condition is re-evaluated at each cycle
- The loop stops when the condition returns
false
Input
The node evaluates its condition from the workflow context variables (context.data.status, context.variables.attempts, context.lastResponse.data, etc.):
{
"status": "processing",
"attempts": 2
}
Output
The While node produces no data of its own: it controls the execution of the nodes of the loop. The context stays accessible to the loop nodes and can be updated by them (e.g. an incremented attempts counter).
Example
Example 1: Wait for a status
Condition: {{order.status}} !== "processed"
Workflow:
- While: As long as the status is not "processed"
- HTTP(S) request: Check the status
- Wait: Wait 5 seconds
- Back to step 1
Example 2: Retry in Do while mode
Condition: context.variables.attempts < 3 && context.data.success === false
Workflow:
- Do while: Execute a first attempt, then continue as long as attempts < 3 and success = false
- HTTP(S) request: Try the operation
- Condition: Check the success
- Increment attempts
Make sure the condition can become false (counter, changing status) and add a Wait node in the loop to avoid a too fast loop that would saturate the execution.