Skip to main content

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:

  1. Loop Through … — starts or continues a loop and emits a Loop ID plus the current item or index
  2. 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 ActionUse when
Loop Through Number RangeAPI pagination (pages 1…N), retry counters, any fixed numeric sequence
Loop Through JSON ArrayA 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

  1. Add Loop Through JSON Array and point it at your array field.
  2. Connect the Actions that should run per item (transform, API call, write to datastore).
  3. End the branch with Continue Loop, wired back to the array loop, using the Loop ID from step 1.

Paginated API loop

  1. Call the API once to learn how many pages exist.
  2. Optionally branch with a comparison (pages > 1) so single-page responses skip the loop entirely.
  3. Loop Through Number Range from the next page index through the last page.
  4. Inside the loop, call the API with page = loop index.
  5. 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

LoopsDivides
You wire loop + continue on the canvasParallelism is built into the Wrk Action
Strong control over order and exit conditionsBest for homogeneous batches with no ordering requirement
Ideal for pagination and step-by-step API workflowsIdeal 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.