<!-- BusyBot node reference — https://busybot.net/tools/loop/ -->

> Node: Loop (`loop`) · Action · v1
> Category: Core Nodes · Credentials: none
> Updated: 2026-08-16

# Loop

> Iterate through body nodes multiple times

## Overview

Iteratively executes a sub-workflow defined by all nodes between this Loop node and its paired Loop End node. Supports three iteration modes: `forEach` (once per input item), `fixedCount` (N iterations), and `whileCondition` (repeat while an expression evaluates to truthy). Each iteration runs the body as a nested workflow execution. The loop body's output can be accumulated across iterations or passed through independently. In `forEach` mode, optional batching groups input items into chunks with a configurable delay between batches for rate limiting. A Loop never creates a graph cycle — the body runs as a nested execution rather than a backward edge on the canvas.

**Category:** Core Nodes  
**Tool Name:** `loop`  
**Version:** 1

**Appearance:** Icon: `loop` | Color: `#8b5cf6`

## Node Type

**Action** — processes input items and produces output

## Input / Output

| Direction | Port(s) |
|-----------|--------|
| Input | `Input` |
| Output | `Done`, `Error` |

## Credentials

This tool does not require any credentials.

### Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| Mode | `options` | Yes | `forEach` | How the loop determines when to iterate. |
| | | | | Options: `forEach` (execute the loop body once for each input item), `fixedCount` (execute the loop body a fixed number of times), `whileCondition` (execute the loop body while a condition is true) |
| Iterations | `number` | Yes | `10` | Number of times to execute the loop body. _(shown when Mode is `fixedCount`)_ |
| Condition | `string` | Yes | `{{ $json.continue === true }}` | Expression that is evaluated after each iteration. The loop continues while this evaluates to a truthy value. Has access to $json (current item), $iteration (0-based index), and $accumulator (array of all prior outputs). _(shown when Mode is `whileCondition`)_ |
| Max Iterations (Safety Limit) | `number` | No | `100` | Maximum number of iterations allowed, regardless of mode. Prevents runaway loops. Applies to all modes as a safety ceiling. |
| Accumulation Strategy | `options` | No | `lastOnly` | How iteration results are accumulated for the final output. |
| | | | | Options: `lastOnly` (output only the final iteration's results), `all` (concatenate outputs from every iteration) |
| Max Concurrency | `number` | No | `1` | Max concurrent items to process. Default is 1 (sequential iteration). Values > 1 are only meaningful in forEach mode with independent iterations. |
| Enable Batching | `boolean` | No | `false` | Group input items into batches. Each iteration processes a batch instead of a single item. _(shown when Mode is `forEach`)_ |
| Batch Size | `number` | Yes | `10` | Number of items per batch. _(shown when Mode is `forEach` and Enable Batching is `true`)_ |
| Delay Between Batches (ms) | `number` | No | `0` | Milliseconds to wait between batches. Useful for rate limiting. No delay is applied before the first batch. Set to 0 for no delay. _(shown when Mode is `forEach` and Enable Batching is `true`)_ |

## Output Data

The `Done` port emits the accumulated results of the loop: the last iteration's items when **Accumulation Strategy** is `lastOnly`, or every iteration's items concatenated when it is `all`. The items are whatever the last node of the loop body produced, so their shape is defined by the body, not by this node. When the error mode is `errorPort`, an iteration that fails emits an error item on the `Error` port and the loop carries on with the next iteration.

Every item handed to the loop body carries a `_loopMeta` object alongside its own JSON:

- `iteration` — 0-based index of the current iteration
- `itemIndex` — position of the item within this iteration's input
- `mode` — the iteration mode in use
- `batchIndex`, `batchSize`, `batchItemIndex`, `totalBatches` — added only when batching is enabled

Read it inside the body with expressions such as `{{ $json._loopMeta.iteration }}`.

If there are no nodes between the Loop and its Loop End, the node passes its input straight through to `Done`.

## Usage Examples

- Loop through each item and enrich with API calls
- Repeat a transformation 5 times to refine output
- Keep calling an LLM until the output passes validation

## Example Configuration

Run the body once per input item, with a safety ceiling:

```json
{ "type": "loop", "parameters": { "mode": "forEach", "maxIterations": 100 } }
```

### Error Handling

| Mode | Behavior |
|------|----------|
| **stop** | Halts workflow on first error |
| **continue** | Skips failed items, passes successful ones through |
| **errorPort** | Routes failed items to Error output port |

## Tips

Iteratively executes body nodes between Loop and Loop End — supports forEach, fixedCount, and whileCondition modes.

### Behavior notes

- **Pair every Loop with a Loop End.** The nodes chained between the two are the loop body; the Loop End marks where the body stops.
- **Max Iterations is a hard ceiling for every mode**, including `fixedCount` — raise it above the iteration count you actually want.
- **`whileCondition` is evaluated after each iteration**, so the body always runs at least once.
- **Batching changes what an iteration is.** With batching on, one iteration processes a whole batch instead of a single item, and Delay Between Batches applies between iterations — never before the first one.