---
title: "Repeat for each (loops) - Workflow Suite"
description: "Repeat steps once for every item of a list, such as the line items of an order or the results of a Shopify query, with clear limits and error handling."
canonical: "https://docs.workflow-suite.app/repeat-for-each"
---

# Repeat for each

**Repeat for each** runs steps once for every item of a list, one item after the other: every line item of an order, every order a query found, every file in a folder. When the list is done, the run continues under **After the loop**.

## Add a loop

1. Press **+** and pick **Repeat for each**.
2. In **List**, pick ONE variable that holds a list, with the variable button on the right. For example:

```liquid
{{ event.payload.line_items }}
```

3. Press **+** under **For each** and add the first step to repeat. Add more steps below it.
4. Choose **When an item fails**: **Stop the loop and fail the run**, or **Go on with the next item**.
5. Optional: set **Maximum items**. Empty means 100; the most is 500.

## What the repeated steps read

| Variable | Holds |
| --- | --- |
| `loop.item` | The current item. Its fields as `loop.item.sku`, `loop.item.id` and so on |
| `loop.index` | The position, starting at 0 |
| `loop.number` | The position, starting at 1 |
| `loop.length` | How many items the list has |
| `loop.first`, `loop.last` | `true` for the first and the last item |
| `loop.parent.item` | In a loop inside a loop: the current item of the outer loop |

Repeated steps also read each other's results for the same item, as usual: `steps.<id>.output`. After a test run the variable picker offers the real fields of an item.

## What steps after the loop read

The results of the repeated steps are cleared between items. After the loop, read the loop's own result, `steps.<loop>.output`:

| Field | Holds |
| --- | --- |
| `count` | How many items the list had |
| `succeeded`, `failed` | How many items went through, and how many failed |
| `results` | Per item: `index`, `status`, and the output of its last step (or the error) |

A result over 4,000 characters is left out of `results`; it stays in the run history. A typical last step is a Log:

```liquid
Archived {{ steps.each_order.output.succeeded }} of {{ steps.each_order.output.count }} orders
```

> [!WARNING]
> **Limits fail loudly, they never cut a list short**
> - A list longer than **Maximum items** fails the step before the first item. Nothing is repeated.
> - One run executes 1,000 steps at most, repeated ones included. 200 items with 5 steps each is the ceiling.
> - A loop that is still working after about 8 minutes starts no further item and fails with a message that says how far it got. In a Test the limit is 45 seconds.
> - A **Wait** step cannot be repeated. To handle items later, start another workflow with a delay from inside the loop.

## When an item fails

- **Stop the loop and fail the run** - the run ends as Failed at that item. Items before it stay done.
- **Go on with the next item** - the item counts as failed, the loop continues, and the run goes on after the loop. A **Fail the run** step inside the loop then fails only the current item. Check `steps.<loop>.output.failed` afterwards if failures matter.

## Loops inside loops

A loop can contain another loop, for example every order, and in it every line item. Inside the inner loop, `loop` is the inner item and `loop.parent` the outer one. Keep the 1,000 step limit in mind: the numbers multiply.

## Where lists come from

- The event: `event.payload.line_items`, `event.payload.discount_codes`, `event.payload.added_tags`.
- A Shopify query: `steps.orders.output.orders.nodes`. See [Every Shopify mutation and query](https://docs.workflow-suite.app/shopify-mutations-and-queries.md).
- A File transfer step that lists a folder: read each file's path as `loop.item.path`. See [Files, SFTP and downloads](https://docs.workflow-suite.app/files-sftp-and-downloads.md).
- A Liquid script step that builds a list, for example from the lines of a CSV file. See [Liquid script step](https://docs.workflow-suite.app/liquid-step.md).
- An HTTP request: a list in `steps.request.output.body`.

## In the run history

A repeated step appears once per item, grouped by item, with what it returned. The loop's own entry comes last, because it is written when the loop ends.

## Related

- [Recipe: nightly cleanup with Repeat for each](https://docs.workflow-suite.app/recipe-archive-completed-orders.md)
- [Conditions](https://docs.workflow-suite.app/conditions.md)
