> ## Documentation Index
> Fetch the complete documentation index at: https://docs.riggery.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Loop

> Repeat the nodes inside the card.

A **Loop** repeats the nodes placed inside its card. Nodes after the card run once.

Connect the previous node into the handle on the left. Connect the first node inside from the handle under the title. Connect the node that runs after the loop from the handle on the right.

<h2 id="each">
  Each item
</h2>

**Each item** reads an array from the previous node's JSON. **Items path** defaults to `items`, which matches [Read records](/graph/tools/state-query): `{ "items": [], "nextCursor": null }`.

On each step, the first node inside receives the current element as its input. **Insert value** on that edge lists **Item** and **Index** (Index starts at 0). A [Code](/graph/tools/code) node on that edge sees the element as `input`.

An empty array finishes with 0 iterations. An array longer than **Max iterations** fails the run before any node inside runs.

<h2 id="while">
  While
</h2>

**While** repeats until the expression is false, or until **Max iterations**. The expression uses the same `input` as [Condition](/graph/condition), plus `index`.

The first node inside receives the Loop input (the previous node's JSON) on every step.

If the expression is still true at the cap, the run succeeds and **Stopped** is `max`.

<h2 id="done">
  After the loop
</h2>

The handle on the right runs once. Its **Result** is JSON:

```json theme={null}
{ "iterations": 2, "stopped": "end" }
```

`stopped` is `empty`, `end`, `condition`, or `max`. Results of the nodes inside are not copied into this JSON.

<h2 id="limits">
  Limits
</h2>

**Max iterations** cannot be higher than 100. A Loop can sit inside another Loop, up to 3 levels. Trigger and Respond cannot be placed inside. One error inside fails the run.

**Run this step** on the Loop runs every iteration. **Run this step** on a node inside runs that node once and uses the Loop **Test input** as the current element.
