Looping
A loop repeats a section of your Wrkflow for each item in a list or each step in a numeric range. Where divides push parallel work inside a single Wrk Action, loops are something you design: you choose what runs on each iteration and when the loop should stop.
The two-Action pattern
Every loop on Wrk is controlled by a pair of Wrk Actions:
- Loop Through … — starts or continues a loop and emits a Loop ID plus the current item or index
- Continue Loop — tells the platform whether to fetch the next item or exit the loop for that Loop ID
Rule of thumb: each loop needs its own Continue Loop, wired back to the loop Wrk Action so you can pass the Continue Loop ID into the loop configuration.
On the canvas, a loop looks like a branch that eventually connects back to the loop Wrk Action — not a separate parallel fan-out like a divide.
Loop types you will see
| Wrk Action | Use when |
|---|---|
| Loop Through Number Range | API pagination (pages 1…N), retry counters, any fixed numeric sequence |
| Loop Through JSON Array | A response field contains an array (docs[], items[], rows[]) and you process each element |
Both types output:
- Loop ID — unique handle for this loop instance; map it into the matching Continue Loop
- Item value or Item index — the current element you process inside the loop body
Set Maximum number of items while testing so a misconfigured loop does not process thousands of records unexpectedly.
What it looks like in practice
Simple array loop
- Add Loop Through JSON Array and point it at your array field.
- Connect the Actions that should run per item (transform, API call, write to datastore).
- End the branch with Continue Loop, wired back to the array loop, using the Loop ID from step 1.
Paginated API loop
- Call the API once to learn how many pages exist.
- Optionally branch with a comparison (
pages > 1) so single-page responses skip the loop entirely. - Loop Through Number Range from the next page index through the last page.
- Inside the loop, call the API with
page = loop index. - Continue Loop wired to the number-range loop.
Always connect the No branch (loop not needed) to your completion path. Otherwise a one-page response can leave the Wrkflow without a clear exit.
Nested loops
For paginated APIs where each page returns its own array, you may nest an inner array loop inside an outer page loop. Each Continue Loop must use the Loop ID for the loop it controls — inner for inner, outer for outer. Reusing the wrong Loop ID is a common cause of early exits or runaway iteration.
For concurrent page + item processing (higher throughput, less predictable log order), see the patterns in Loop basics.
Loops vs divides
| Loops | Divides |
|---|---|
| You wire loop + continue on the canvas | Parallelism is built into the Wrk Action |
| Strong control over order and exit conditions | Best for homogeneous batches with no ordering requirement |
| Ideal for pagination and step-by-step API workflows | Ideal for enriching or transforming many rows at once |
Many Wrkflows combine them: a loop walks API pages in order while a dividing Wrk Action processes every row on the current page in parallel.
Related resources
- Working with large data — Overview
- Divides
- Loop basics tutorial
- Fields to Capture — extract only the fields you need inside a loop body
- Loop Through JSON array reference
- Loop Through Number Range reference
- Continue Loop reference