while

Repeats a block of commands while a condition stays true.

Fields

FieldTypeDefaultDescription
conditionrequiredPython expressionBoolean expression re-evaluated before each iteration. When false, the loop stops.
docommand blockCommands executed on every iteration while the condition is true.

Example

"var": { "page": 1, "items": [] },
"while": {
  "condition": "{ page <= 5 }",
  "do": {
    "api": {
      "profile": "catalog",
      "queryParams": { "page": "{ page }" }
    },
    "var": {
      "items": "{ items + result['items'] }",
      "page": "{ page + 1 }"
    },
    "break": "{ not result['hasMore'] }"
  }
}

Rules

  • The condition is evaluated before every iteration, including the first.
  • A loop may not run more than the max loop iterations set in Runtime limits. Exceeding the limit fails the agent. The count restarts each time the loop is entered.
  • A long loop yields to other work from time to time, so that the agent's overall runtime limit can be enforced.
  • Use break to leave the loop early and continue to skip to the next iteration.