Skip to content

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.

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, 8
from = 5, to = 5 → 0 passes (the flow continues without entering)
  • from, to and step are 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. A step of 0 or a negative one with from < to never reaches the end and leaves the loop spinning; always use a positive step.
  • 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.
ParameterTypeDefaultDescription
fromint—Start index (included). Rounded to an integer.
toint—End index (excluded): the loop runs while the index is < to. Rounded to an integer.
ParameterTypeDefaultDescription
stepnumber1How much the index increases per pass. Must be greater than 0.
indexVariablestring"i"Name of the variable that holds the current index.

Activities that run on each pass.

This activity does not return a value. What it produces is the indexVariable variable, updated on each pass.

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 " + page
MessageCause and fix
'activities' is required.The loop has no activities lane. Add at least one activity inside.
The loop never endsstep is 0 or negative, or the body never reaches an expected Break. Use a positive step.
One pass fewer than expectedto is exclusive. Add 1 to it.
The value of from, to or step cannot be converted to a numberThe expression returned a text that is not a number. Convert it with num(...) or check the source variable.
  • For Each — when you loop through the elements of a list or table, not a count.
  • While — when you don’t know how many passes, but depend on a condition.
  • Break / Continue — exit the loop or skip to the next pass.