Looping
Sometimes the same logic has to run for every entry in a list - one task per reviewer, one document per order line, one call per record. Instead of copying a branch over and over, you use a loop: a single step that runs its loop path once for each item and then moves on.
How a loop runs
A loop step has two main paths:
- A loop path that runs once per iteration, with the current item (or, for a count-based loop, the current index) made available to the steps on it.
- A continue-after path that runs once, after the last iteration has been processed.
The engine keeps track of where it is between cycles, so you don’t manage an index yourself. If there is nothing to iterate - an empty list, or a count of zero - the loop path never runs and execution goes straight to the continue-after path. Put any “after the loop” logic there, not on the loop path.
Loops can also surface an error path for when the list can’t be read, which you can handle like any other failure. See Error Handling.
Ways to loop
There are three loop actions, depending on what you are looping over:
- Loop over Array - iterate the items of an array symbol you already hold in the process.
- Loop over CSV - read a CSV file one row at a time, writing each row’s columns into symbols.
- Loop - repeat a fixed number of times. You set a Count - which can come from a number symbol, so the number of passes is decided at runtime - and each pass exposes the Current Index so steps can tell which iteration they are on.
All three follow the same loop path / continue-after pattern; they differ only in what they iterate over.
Making the current value available
Each pass exposes its current value - the array item, the CSV row, or the count loop’s current index - so later steps in the loop can use it. Map it into a symbol (or use the step’s automatic context updates) before any logic that needs it, so the value is in place when those steps run.
Collecting results
A loop processes items one at a time, so to gather an output from every pass, append to an array as you go with Push to Array, then use the finished array after the loop. Reset that array before the loop if it might already hold values.
Looping in parallel
The loops above run items in sequence. When items are independent and you want them to run at the same time, launch a subprocess per item and join them later with Await Subprocess. See When to use a sub-process.
Related
- Loop over Array - loop over a list you hold in the process.
- Loop over CSV - loop over the rows of a CSV file.
- Branching & Merging - how paths split and join, including running work in parallel.
- Push to Array - collect a result from each pass.