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
- When an element is a tuple and several loop variables are given, the tuple is unpacked into the variables in order.
- The loop variables are locals of the function. The loop variables are removed when the loop ends.
- A
fornested inside anotherformay not reuse the outer loop's variable names. maxIterationsstops the loop quietly when the count is reached. WithoutmaxIterations, the max loop iterations setting in Runtime limits applies.- The
askandinvokecommands are not allowed inside aforblock, nor in any function called from aforblock.

