While
Controlled node
Overview
The While node repeatedly executes a loop while a specified condition is met. It reads a variable from the variable store on each iteration and compares it using a configurable operation and break value. The loop continues as long as the condition evaluates to true, and stops when the condition becomes false.
This is useful for scenarios like pagination, polling, or any situation where you need to repeat an action until a certain state is reached.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Run | Event | Trigger the node to run | - |
| Variable Name | Text | The name of the variable to check on each iteration | - |
Outputs
| Output | Type | Description |
|---|---|---|
| Loop | Event | Fires on each iteration when the condition is met |
| Index | Number | The current iteration index (0-based) |
| Finished | Event | Fires when the loop has finished (condition is no longer met) |
Settings
| Setting | Type | Description | Default |
|---|---|---|---|
| Operation | Enum | The comparison operator to use (==, !=, <, >, <=, >=) | == |
| Break Value | Text | The value to compare the variable against. The loop continues while the condition is true | null |
How It Works
- The node reads the value of the variable specified in Variable Name from the variable store
- It compares this value against the Break Value using the selected Operation
- If the condition is true, the Loop event fires and the iteration continues
- If the condition is false, the Finished event fires and the loop stops
- The Index output increments with each iteration
Example Use Cases
Pagination with Cursor
Check if a cursor variable is not null to continue fetching paginated data:
- Variable Name:
cursor - Operation:
!= - Break Value:
null
The loop will continue as long as cursor != null, and stop when the cursor becomes null.
Polling Until Complete
Check if a status variable equals "completed":
- Variable Name:
status - Operation:
!= - Break Value:
completed
The loop will continue while status != "completed", and stop when status becomes "completed".
Count-Based Loop with Variable
Check if a counter is less than a target:
- Variable Name:
counter - Operation:
< - Break Value:
10
The loop will continue while counter < 10, and stop when counter reaches 10 or more.
Important Notes
- The variable is read fresh from the variable store on each iteration, so you must update it within the loop using a Set Variable node
- The loop has a maximum iteration limit to prevent infinite loops
- If the condition is false on the first iteration, the Finished event fires immediately without executing the loop body
- The Index starts at 0 and increments with each iteration