# Loops & Iteration

> Two ways to repeat work in Glow: a setting on one step, and the Repeater step for a body of several.

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.

Two loop shapes: Run for each item fans one step out over a list, while the Repeater sends the flow back around a circuit. See /build/action-steps/loops.

| Use                                                                              | When                                                                              |
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| **[Run for each item](/build/action-steps/loops/run-for-each-item)** — a setting | One step needs to run once per item. Most cases.                                  |
| **[Repeater](/build/action-steps/loops/repeater)** — a step on the canvas        | Several 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 job                                                                | Use                       | Why                                                                |
| ---------------------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------ |
| Email every person who filled in this week's form                      | **Run for each item**     | One step — the email — per person.                                 |
| Write each row of a CSV into a spreadsheet                             | **Run for each item**     | One step per row.                                                  |
| Post a Slack message for every failed payment                          | **Run for each item**     | One step per payment.                                              |
| For each lead: look up the company, score it, write it back to the CRM | **Repeater**              | Three steps per lead, and step two needs step one's answer.        |
| For each invoice: read the PDF, check the total, file it or flag it    | **Repeater**              | The body branches, so it cannot be one step.                       |
| Fetch pages 1 to 10 of an API                                          | **Repeater**, fixed count | No list to walk — a counter, with `{{ item.$index }}` as the page. |
| Retry a flaky call five times with a wait between                      | **Repeater**, fixed count | The 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.

| Reference           | What 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](/build/action-steps/filter-items) 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](/build/action-steps/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](/manage/billing/credits-and-allowances) 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](/build/action-steps/filter-items) before it reaches the loop. See [System Limits](/reference/system-limits) for the concurrency your plan allows.

## What's Next?

- [Run for each item](/build/action-steps/loops/run-for-each-item): the setting, in full.
- [Repeater](/build/action-steps/loops/repeater): the step, its circuit, and how to pace it.
- [Variable Syntax](/reference/variable-syntax): the full reference for `{{ }}`.
