for
Runs a block of commands once for each element of an iterable: a list, a dict, or any Python iterable or async iterable that an expression produces.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
iterrequired | dynamic string or list or object | What to iterate over: a list, dict or any Python iterable. | |
loopVar | list of name or name | Names bound on each iteration. For a tuple of N elements, give N names. | |
do | command block | Commands executed for each element produced by the iterator. | |
maxIterations | dynamic string or integer | Caps the number of iterations. |
Example
"for": {
"iter": "{ result['properties']['periods'][:8] }",
"loopVar": "period",
"do": {
"var": {
"lines": "{ lines + [f'In {period['number']} hours: {period['temperature']} and {period['shortForecast']}'] }"
}
}
}Iterating a dict binds the dict's keys. To get key and value together, iterate { d.items() } and give two loop variables:
"for": {
"iter": "{ prices.items() }",
"loopVar": ["sku", "price"],
"do": {
"progress": "{ f'{sku} costs {price}' }"
}
}Rules
itermay also be a literal JSON list or object. An expression inside such a literal is evaluated like any other.- When an element is a tuple and several loop variables are given, the tuple is unpacked into the variables in order. A single loop variable over pairs, such as
{ d.items() }, gets the whole pair. - The loop variables are locals of the function, removed when the loop ends. They follow the rules for variable names: no reserved name, no Python keyword.
- A
fornested inside anotherformay not reuse the outer loop's variable names. maxIterationsstops the loop quietly when the count is reached, and0means zero iterations. Without it, a loop that reaches the max loop iterations setting in Runtime limits fails the run with a message, aswhiledoes.askis not allowed inside aforblock, nor in any function called from one.

