Skip to main content

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​

ParameterTypeRequiredDefaultDescription
ConditionJavaScript (boolean)✅—Run JavaScript code that returns a boolean to determine whether we stay in the loop or exit it.
Loop modeWhile / Do while✅—Behavior choice: While or Do while.

Condition​

Run JavaScript code that returns a boolean:

  • true: the loop continues
  • false: 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​

  1. The condition is evaluated
  2. According to the chosen mode:
    • While: executes the loop if the condition is true
    • Do while: first executes the loop, then checks the condition
  3. The condition is re-evaluated at each cycle
  4. 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:

  1. While: As long as the status is not "processed"
  2. HTTP(S) request: Check the status
  3. Wait: Wait 5 seconds
  4. Back to step 1

Example 2: Retry in Do while mode​

Condition: context.variables.attempts < 3 && context.data.success === false

Workflow:

  1. Do while: Execute a first attempt, then continue as long as attempts < 3 and success = false
  2. HTTP(S) request: Try the operation
  3. Condition: Check the success
  4. Increment attempts
Infinite loop risk

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.

See also​