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

# Loop

> Iterate over items or repeat steps a fixed number of times.

The **Loop** node repeats a set of steps. It supports three iteration modes: forEach, while, and times.

## Loop modes

### ForEach

Iterates over each item in an array. The current item and index are available to nodes inside the loop body.

| Field | Description |
| - | - |
| **Array** | The array to iterate over (reference a previous node's output) |
| **On iteration error** | **Stop the run** (default): the first failing item fails the run. **Continue with the next item**: the failure is recorded and the remaining items still run; the run ends as failed once every item has had its turn, so failure notifications still fire. |

### While

Repeats as long as a condition is true. Evaluates the condition before each iteration.

| Field | Description |
| - | - |
| **Condition** | The expression to evaluate before each iteration |
| **Max iterations** | Safety limit to prevent infinite loops |

### Times

Repeats a fixed number of times.

| Field | Description |
| - | - |
| **Count** | Number of iterations |

## Output handles

| Handle | Description |
| - | - |
| **Body** | Connect the nodes that should execute on each iteration |
| **Complete** | Continues here after all iterations are finished |

## Accessing loop variables

Inside the loop body, two special variables are injected on each iteration:

| Variable | Default name | Description |
| - | - | - |
| **Item variable** | `item` | The current array element (forEach mode) |
| **Index variable** | `index` | The current iteration index (0-based) |

You can customize these names in the loop node properties panel. Use them in any template expression inside the loop body:

| Expression | Resolves to |
| - | - |
| `{{ item }}` | The entire current element (preserves type: object, string, number, etc.) |
| `{{ item.email }}` | A specific field on the current element |
| `{{ item.address.city }}` | Nested field access |
| `{{ index }}` | Current iteration index: `0`, `1`, `2`, ... |

> [!NOTE]
>
> When `{{ item }}` is the **entire value** (not mixed with other text), the original type is preserved. For example, if `item` is an object, `{{ item }}` resolves to that object, not a JSON string. When mixed with text like `https://api.com/{{ item.id }}`, it resolves to a string.

## Example: Fetch users and post each to a webhook

This example fetches a list of users from an API, then loops over each user and sends their data to a webhook.

### Canvas layout

```
[Trigger] → [Fetch Users] → [Loop] ─── body ───→ [Post to Webhook]
                                    └── complete ─→ [Send Summary]
```

### Step 1: Fetch Users (Connector node, direct mode)

| Field | Value |
| - | - |
| **Connector** | HTTP Requests |
| **Runner mode** | Direct |
| **Tool** | `http-get` |
| **Tool args** | `{"url": "https://jsonplaceholder.typicode.com/users"}` |
| **Output variable** | `users` |

### Step 2: Loop (forEach)

| Field | Value |
| - | - |
| **Loop type** | ForEach |
| **Array** | `{{ users.data }}` |
| **Item variable** | `item` |
| **Index variable** | `index` |

The array path `users.data` navigates into the HTTP response: `users` (output variable) is the parsed HTTP response object `{ data, status, headers, statusText }`, and `.data` is the response body (here a JSON array of user objects).

### Step 3: Post to Webhook (Connector node inside loop body, direct mode)

| Field | Value |
| - | - |
| **Connector** | HTTP Requests |
| **Runner mode** | Direct |
| **Tool** | `http-post` |
| **Tool args** | `{"url": "https://example.com/webhook", "body": "{{ item }}"}` |

On each iteration, `{{ item }}` resolves to the current user object (e.g., `{"id": 1, "name": "Leanne Graham", "email": "Sincere@april.biz", ...}`).

You can also map individual fields:

```json theme={null}
{
  "url": "https://example.com/webhook",
  "body": {
    "name": "{{ item.name }}",
    "email": "{{ item.email }}",
    "city": "{{ item.address.city }}"
  }
}
```

### Step 4: Send Summary (Connector node after loop completes)

Connect from the loop's **Complete** handle. This node runs once after all iterations are finished. The loop's collected results are available via its output variable.

## When an item fails

With **Continue with the next item**, a failed iteration leaves `{ "error": { "message", "code" }, "index" }` in its slot of the loop's result array instead of a value, and the failures alone are available as `{{ result_<node id>_failures }}`, a list of `{ index, message, code }`. The loop's node id is shown under the setting, so for a node with id `loop-1` the variables are `{{ result_loop-1 }}` and `{{ result_loop-1_failures }}`. Nodes after the loop can act on either, for example to email the rows that did not import. The run still finishes as **Failed**, with the count and the first failure in its error, so an ERROR notification rule reports partial imports the same way as total ones.

Some failures stop the run whatever this setting says, because they are decisions about the run rather than about one item: a Cancel node, an approval that was rejected, the account running out of credits, and the per-run attachment download cap.

Use it for per-row imports where one bad row must not block the rest. Pair it with a lookup that skips rows already imported, so a re-run after fixing the bad rows does not create duplicates.

## Tips

* Always set a **max iterations** limit on while loops to prevent runaway execution.
* The loop collects results from each iteration; the complete output is an array of all iteration results.
* For parallel processing of array items, consider using a [Parallel](https://docs.condotta.ai/workflow-editor/nodes/parallel.md) node instead.

> [card] [Try this free for 14 days](https://preview.condotta.ai/signup)
>
> Start a 14-day trial on Band 1. At day 14, choose your band, or stop.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.