Loops
Repeat steps with For each, For range and While, control them with Break and Continue, and stay within RPA Plus's loop limits.
Trang này chưa có bản tiếng Việt. Nội dung tiếng Anh được hiển thị bên dưới.
Repetition in RPA Plus always uses a loop node. A loop is a container: the steps to repeat form a chain that starts at its body output, and when the loop is done the workflow continues through the loop's next output. You cannot draw a connection back to an earlier node — the canvas refuses cycles.
Every loop is bounded, so a workflow can never spin forever.
For each
For each (for_each) runs body once per item of a list.
| Parameter | Default | Meaning |
|---|---|---|
items | — | The list, usually an expression such as {{ rows }} |
item_var | item | Name of the current item inside the body |
index_var | index | Name of the position (0, 1, 2…) |
max_iterations | 10,000 | Up to 100,000; a longer list fails with loop_limit before the first iteration |
items can also be an object — each item is then {key, value} — or text, in which case each non-empty line is an item.
{"id": "each_row", "type": "for_each",
"params": {"items": "{{ rows }}", "item_var": "row"}}Inside the body, {{ row.email }} reads the current row and {{ index + 1 }} its 1-based position.
Typical sources of lists: Read CSV / Read Excel (one object per row when the file has a header), Extract repeated items ({{ found.items }}), Get table data ({{ table.rows }}), Get links ({{ page_links.links }}), Get text with all on, Split text, and HTTP request responses ({{ api.json.items }}).
For range
For range (for_range) counts from start (0) up to, but not including, end, by step (1). The counter is called i unless you set var, and index holds the iteration number. step may be negative; it cannot be 0. A range may have at most 100,000 steps.
{"type": "for_range", "params": {"start": 1, "end": "{{ pages + 1 }}", "var": "page"}}Useful for addresses with a page number: https://intranet.example/reports?page={{ page }}.
While
While (while) checks its condition before each iteration and runs body while it is true. The condition is a bare expression (no braces), for example page_no <= max_pages. max_iterations (1,000 by default, up to 100,000) is mandatory: reaching it fails the step with loop_limit — a deliberate stop for a condition that never turns false.
Inside the body, index counts the iterations. Change the variables the condition depends on (with Increment, Set variable or Save to), or leave with Break.
Break and Continue
- Break (
break) leaves the innermost loop; the workflow continues after the loop. - Continue (
continue) skips the rest of the body and starts the next iteration.
Both are only valid inside a loop body (the Problems tab reports them elsewhere), and both are usually placed in an If / Else branch:
While page_no <= max_pages
└ body: Get table data → Set variable rows = {{ rows + table.rows }}
→ Count elements (next link) → If has_next == 0
└ then: Break
→ Click (next link) → Wait for page load → Increment page_noThis is the shape of the Collect a paginated table template.
Collecting results in a loop
- Append to list adds one value per iteration to a list variable (up to 100,000 items). Declare the variable with a default of
[], or let the first append create it. - Add result row adds a row to the run's results, which appear in the Output tab, the task's Results and the CSV/Excel download (up to 10,000 rows per run).
- After the loop, write everything at once with Write CSV or Write Excel.
{"type": "append", "params": {"name": "results",
"value": {"input": "{{ row[column] }}", "result": "{{ answer }}"}}}Nested loops and variables
Loops can be nested; give each one its own item_var (for example row and cell) so the inner loop does not hide the outer item. Loop variables exist only inside their body. Setting a variable that a loop defines changes it for that iteration; other variables are shared by the whole run.
Limits that protect every run
Beyond each loop's own limit, every run has:
- a time limit — the workflow's Time limit per run (seconds), a task's Timeout per run (s), or the default in RPA Plus → Settings (600 s unless you change it);
- a step budget — Maximum steps in the workflow settings (10,000 by default), which counts every node executed, including each iteration's nodes and nodes of called workflows.
Exceeding them fails the run with run_timeout or step_limit. For a loop over many items, raise the limits rather than splitting the work blindly, and use Delay between iterations if the website you work with asks for a slower pace.
Repeating on failure
To repeat a part of the workflow until it succeeds, do not build a While loop around it: use Retry block (retry_block), which runs its body again up to attempts times with delay_ms between attempts. See Error handling.