For Loop
For Loop
Section titled “For Loop”Type: for-loop · Package: Core Activities v1.0.8
Repeats a block of activities a counted number of times, keeping a numeric index that increases on each pass. Use it when you know how many times to repeat (go through 10 pages, generate 5 reports) and you are not looping through the elements of a collection.
How it works
Section titled “How it works”Counts from from (included) up to to (excluded), adding step on each pass. On each iteration it stores the current value in the indexVariable variable and runs the activities.
from = 0, to = 3, step = 1 → index takes 0, 1, 2 (3 passes; 3 does NOT run)from = 1, to = 11, step = 1 → index takes 1, 2, …, 10 (10 passes)from = 0, to = 10, step = 2 → index takes 0, 2, 4, 6, 8from = 5, to = 5 → 0 passes (the flow continues without entering)from,toandstepare rounded to integers before starting; the index is always an integer.- The loop only counts up: it continues while the index is less than
to. Astepof0or a negative one withfrom < tonever reaches the end and leaves the loop spinning; always use a positivestep. - It supports Break and Continue inside the body. Before each pass the loop checks whether the execution was terminated, so Terminate stops it between one pass and the next.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
from | int | — | Start index (included). Rounded to an integer. |
to | int | — | End index (excluded): the loop runs while the index is < to. Rounded to an integer. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
step | number | 1 | How much the index increases per pass. Must be greater than 0. |
indexVariable | string | "i" | Name of the variable that holds the current index. |
Sub-flows
Section titled “Sub-flows”activities required
Section titled “activities required”Activities that run on each pass.
Output
Section titled “Output”This activity does not return a value. What it produces is the indexVariable variable, updated on each pass.
Example
Section titled “Example”Go through the first 5 pages of a web listing:
For Loop from = 1 to = 6 indexVariable = page └─ activities: Page Navigate url = "https://portal.example.com/list?page=" + page Log level = info message = "Processing page " + pageCommon errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'activities' is required. | The loop has no activities lane. Add at least one activity inside. |
| The loop never ends | step is 0 or negative, or the body never reaches an expected Break. Use a positive step. |
| One pass fewer than expected | to is exclusive. Add 1 to it. |
The value of from, to or step cannot be converted to a number | The expression returned a text that is not a number. Convert it with num(...) or check the source variable. |