Loop context and iteration variables
When a loop step executes, the system creates a loop context that makes iteration data available to every step inside the loop body. You reference this data by using the ${loop.*} expression prefix.
Variables available inside the loop body
| Expression | Available in | Description |
|---|---|---|
${loop.item} |
for each | The current item from the collection. |
${loop.index} |
for each | The zero-based index of the current iteration (0, 1, 2, ...). |
For example, if a For each loop iterates over a list of servers, each step in the loop body can reference ${loop.item} to get the current server name and ${loop.index} to get the iteration number.
Access nested fields in complex items
When a For each loop iterates over a list of objects, you can access nested fields directly with dot notation. For example, if each item in the collection is an object with a name field, you can reference ${loop.item.name} to get that field value.
If a previous step returns a list of user records:
[{"name": "Alice", "role": "admin"}, {"name": "Bob", "role": "operator"}]Inside the loop body, ${loop.item.name} resolves to "Alice" on the first iteration and "Bob" on the second.
Access loop results from downstream steps
After a loop completes, downstream steps on the done path can reference the loop output by using the loop step name. The available output fields are:
| Expression | Description |
|---|---|
${loop_step.status} |
The completion status of the loop. |
${loop_step.iteration_count} |
The total number of iterations that ran. |
${loop_step.iteration_results} |
A collection of output values from each iteration. |
The iteration_results field organizes output by step name and field. Each entry contains an array with one value per iteration. For example, if a loop body contains a step named check_status that outputs a result field, ${loop_step.iteration_results} contains the result value from every iteration.
Variable scoping in nested loops
If you place a loop inside another loop, each loop maintains its own context. Steps inside the inner loop always reference ${loop.item} and ${loop.index} for the innermost enclosing loop only. The inner loop's config is the bridge that can reference the outer loop's data and restructure it for its own body steps.