Skip to content

Step: While

  • Key: while
  • Category: Workflow Control
  • Description: Repeat nested steps while a condition evaluates to true.

Inputs

  • condition (long-text, required): JavaScript-style expression evaluated against the current flow context, for example retryCount < 3 && status !== "done".
  • maxIterations (number, optional): Safety limit for loop runs. The default is 200; the runtime caps the value at 2000.

Loop Context

During each iteration, nested steps can read:

  • iteration: Zero-based iteration index.
  • _while: Object containing iteration, run, and isFirst.

The runtime restores any previous iteration and _while values after the loop finishes.

Outputs

  • iterations (number): Number of completed iterations.
  • results (array): Per-iteration nested step results.
  • errors (array): Condition evaluation errors, nested step errors, or max-iteration errors.
  • lastIteration (object | null): Last iteration result, or null if nothing ran.

Notes

  • The condition is checked before each iteration.
  • Make sure nested steps update the variables used by condition; otherwise the loop runs until maxIterations is reached.
  • Prefer each when you already have a fixed array. Use while for polling, retries, countdowns, and condition-based workflows.

Example Use Cases

Retry until success: Poll an external API and keep looping while status !== "completed".

Countdown: Decrement a numeric variable until the condition becomes false.

Pagination: Fetch a page, append the results to an array, update nextPage, and stop when no next page remains.

Built with VitePress