Iterates over an array, executing a nested set of nodes for each item. Think of it as a for-each loop. Use this to process lists, batch operations, or apply the same logic to multiple records.

LoopNode loops an input list and executes the body nodes for each item.

## How It Works

The Loop node takes an array as input and executes the nodes connected to its `loop` output socket once per array element. Each iteration receives a single item, processes it, and the results are collected.

After all iterations complete, the collected results flow to the `output` socket as an array.

**Example**:
```
Input: [1, 2, 3]
Loop body: Multiply by 2
Output: [2, 4, 6]
```

Loops are **strictly sequential**. Item 2 doesn't start until item 1 finishes. This ensures predictable execution order and avoids overwhelming downstream services.

## Inputs & Outputs

**Input**: An array of any type. Each element becomes one iteration.

**Outputs**:
- **loop**: A single array element. Connect your processing logic here.
- **output**: An array of results after all iterations complete.

**Context**: Each iteration has access to an `iteration` context variable (0-based index).

**Example flow**:
```
Input: [{"id": 1}, {"id": 2}, {"id": 3}]
Loop body: Fetch user details for each ID
Output: [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, {"id": 3, "name": "Charlie"}]
```

## Skipping an Iteration

A loop body that returns `skip(reason)` contributes nothing to the collected array. The iteration ran and decided it had nothing to add, so skip works as a filter.

```
Input: [1, 2, 3]
Loop body: return item === 2 ? skip('not interesting') : item * 2
Output: [2, 6]
```

The output array is shorter than the input. Nothing marks where the skipped items were.

## Cross-Boundary Wiring

You can wire parent workflow nodes directly to loop body nodes. This allows you to pass configuration, API keys, or other data to nodes within the loop body.

**Example:**
```
[Constant: API Config] → api_key, base_url
    ↓
[Table: Query] → all users
    ↓
[Loop]
    ↓ (loop)
[HTTP GET: Fetch user]
    - URL: {{ base_url }}/users/{{ item.id }}
    - Headers: Authorization: Bearer {{ api_key }}
```

The `api_key` and `base_url` from the parent Constant node are accessible in the loop body's HTTP node.

## Example: Enrich User Records

```
[Table: Query] → all users
    ↓
[Loop]
    ↓ (loop)
[HTTP GET: Fetch profile from external API]
    ↓
[Table: Upsert] → update user with enriched data
    ↓ (output)
[Discord Send: "Enriched users"]
```

The workflow queries all users, loops over them, fetches external profile data for each, and updates the database.

## Example: Send Personalized Emails

```
[Table: Query] → active subscribers
    ↓
[Loop]
    ↓ (loop)
[Template: Render email body] → use {{ item.name }}, {{ item.preferences }}
    ↓
[HTTP POST: Send via email API]
    ↓ (output)
[Table: Insert] → log sent emails
```

Each subscriber gets a personalized email. The loop ensures emails are sent sequentially.

## Example: Process with Iteration Index

```
[Input] → [10, 20, 30]
    ↓
[Loop]
    ↓ (loop)
[Lua Script: return { value = input, index = context.iteration }]
    ↓ (output)
[Table: Insert] → [{"value": 10, "index": 0}, {"value": 20, "index": 1}, {"value": 30, "index": 2}]
```

The `iteration` context variable (0-based) is available inside the loop body for tracking position or conditional logic.

## Data Piping Invariant

A downstream node only sees what is explicitly wired into it. The `loop` socket emits a single array element; the `output` socket emits an array of collected results. Neither socket carries unrelated upstream data. If you need to upsert the original row after a side-effect inside the loop body, keep a parallel wire from the loop's `loop` output (or the original data source) to the write node, or reconverge branches with a `Merge` node in `select` mode. Do not place write/upsert nodes in thin air expecting data to appear from an unrelated upstream branch.

## Tips

- **Loops are strictly sequential.** There is no parallelism—each iteration completes before the next starts. This ensures predictable execution order and avoids overwhelming downstream APIs.
- **The output is always an array.** Even if your loop body returns a single value per iteration, the `output` socket collects them into an array.
- **Empty arrays are fine.** If the input array is empty, the loop body never executes, and `output` is an empty array.
- **Output is an array.** The `output` socket collects results from all iterations into an array.
- **Access iteration index.** Use `context.iteration` inside the loop body to get the current index (0-based).
- **Errors stop the loop.** If one iteration fails, the entire loop fails. Use error handling nodes inside the loop if you need graceful degradation.
