Skip to Content
๐Ÿ›  Build๐Ÿ›  Action StepsLoops & IterationLoops & Iteration

Loops & Iteration

Glow repeats work in two ways, and the difference is a shape rather than a rule. Run for each item is a setting that runs one step once per entry. The Repeater step repeats a body of several steps.

Use them to send one message per customer, enrich fifty leads, or page through an API.

A loop is always something you drew

Nothing in Glow starts looping on its own. A step given a list of fifty records does not quietly run fifty times: it runs once, with the list as its input, until you say otherwise.

That is deliberate. Repeating is either a setting you switched on, visible on the stepโ€™s badge, or a Repeater with a line running back into it. Either way you can point at the thing that makes it repeat.

Two things follow, and both save time later:

  • You can read a canvas and know what it does. Nobody has to open every step to find the one that fans out over a thousand records.
  • You can plan for repeated work. The loop is visible on the canvas, so you can review the steps and item count before running it.

Which one? Count the steps

How many steps does the work take per item? That one question decides it.

TriggerSend emailEach itemSummariseitem 1item 2item 3โ€ฆOne step, one run per entry. The canvas stays a straight line.
UseWhen
Run for each item โ€” a settingOne step needs to run once per item. Most cases.
Repeater โ€” a step on the canvasSeveral steps run together per item, or the body repeats a fixed number of times.

One step โ€” sending an email per customer, writing each row to a sheet โ€” needs no loop on the canvas at all. Open that stepโ€™s repeat badge, switch it to Each item, and choose the list.

More than one step โ€” look the customer up, decide something, write it back โ€” is a loop body, and a body needs the Repeater step.

Repeater also covers the cases with no list. A fixed number of times runs the body N times, with {{ item.$index }} as the counter โ€” that is how you call page 1, 2, 3 of an API. Until a rule is met keeps going until what a pass produced satisfies a rule you write, for when the finish line is a result rather than a count.

Worked examples of each

Real jobs, and which mechanism each one needs.

The jobUseWhy
Email every person who filled in this weekโ€™s formRun for each itemOne step โ€” the email โ€” per person.
Write each row of a CSV into a spreadsheetRun for each itemOne step per row.
Post a Slack message for every failed paymentRun for each itemOne step per payment.
For each lead: look up the company, score it, write it back to the CRMRepeaterThree steps per lead, and step two needs step oneโ€™s answer.
For each invoice: read the PDF, check the total, file it or flag itRepeaterThe body branches, so it cannot be one step.
Fetch pages 1 to 10 of an APIRepeater, fixed countNo list to walk โ€” a counter, with {{ item.$index }} as the page.
Retry a flaky call five times with a wait betweenRepeater, fixed countThe body is a call plus a Wait, repeated a set number of times.

The pattern behind the table: count the steps the work takes for one item. One step is a setting; more than one is a Repeater.

What they share

Both bind the current item to {{ item }}, so what you write inside the loop is the same either way.

ReferenceWhat it holds
{{ item }}The entry being processed
{{ item.$index }}Position in the list, counting from 0
{{ item.$total }}How many items there are altogether

Both also collect what every pass produced into {{ N.results }}, with {{ N.items }} carrying per-item detail and {{ N.stats }} the totals.

Filter uses a different form. Its rules take {{ $item }} and {{ $itemIndex }}, with the dollar sign at the front. Filter evaluates its rules itself rather than running a pass per item, which is why the two look alike but are not interchangeable.

One mechanism per list, never both

A step inside a Repeaterโ€™s body already runs once per pass, so its own Each item mode is switched off there. Going the other way, the canvas refuses a connection that would close a loop around a step set to repeat on its own.

Why it works that way: both answer the same question, which is how many times a step runs. Each has its own answer. A step set to Each item over 50 records, inside a Repeater running 50 passes, would run 2,500 times. Almost nobody means that, and it is expensive to discover by running it.

So the rule is one mechanism per list:

  • Work that takes one step per item: the stepโ€™s own Each item setting.
  • Work that takes several steps per item: a Repeater, with those steps plain inside its body.

For a list inside a list โ€” every order for every customer โ€” use two Repeaters in sequence rather than one inside the other. Flatten the inner list with a Combine step first, then loop over the result.

Plan for loop usage

Usage depends on the steps that run and the work they perform on each pass. Standard action steps consume 1 Step credit per item pass, while control steps are free. See Step Credits, Tokens & Storage for how repeated work and failed attempts are counted.

Where the list comes from somewhere you do not control, cap it โ€” with Repeaterโ€™s Safety limit, or with a Filter before it reaches the loop. See System Limits for the concurrency your plan allows.

Whatโ€™s Next?