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

# Loop (For Each)

Iterates over an array and executes child nodes sequentially for each item. Supports nesting up to 10 levels. Inner loop: $item/$index, outer loop: $parent_item/$parent_index, any ancestor: $for.{nodeID}.item/$for.{nodeID}.index. Max 1000 iterations per loop. Runtime budget: 10,000 total nodes. Loop body nodes go in loopBody field. Post-loop nodes go in children field (execute after all iterations finish).

Logic action Logic

Iterates over an array and executes child nodes sequentially for each item. Supports nesting up to 10 levels. Inner loop: $item/$index, outer loop: $parent_item/$parent_index, any ancestor: $for.&#123;nodeID&#125;.item/$for.&#123;nodeID&#125;.index. Max 1000 iterations per loop. Runtime budget: 10,000 total nodes. Loop body nodes go in loopBody field. Post-loop nodes go in children field (execute after all iterations finish).


## At a Glance

| Field | Value |
| --- | --- |
| Action ID | `for-each` |
| Category | Logic |
| Connector | Not required |
| Requires gas | No |
| Funds movement | None declared |
| Tags | `logic`, `loop`, `iteration`, `for-each`, `control-flow` |

## Payload Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `array` | `array` | Yes | Array to iterate over \(can be template variable like &#123;&#123;node.result.items&#125;&#125;\) |

## Result Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `iterations` | `array` | Yes | Array of iteration results |
| `iterationCount` | `integer` | Yes | Total number of iterations executed |
| `lastAdvancedIteration` | `integer` | No | Index of the last iteration that was advanced \(iterationCount - 1\) |
| `status` | `string` | Yes | Loop execution status |

## Examples

**Workflow node**

```json
{
  "type": "for-each",
  "payload": {
    "array": []
  },
  "children": []
}
```
  **Test with API**

```bash
curl -X POST "https://api.b3os.org/v1/actions/for-each/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "array": []
  }
}'
```

**Use expressions for dynamic values**

Payload fields can use workflow expressions such as `{{$trigger.body.amount}}`, `{{$nodes.fetch.result.price}}`, and `{{$props.asset}}` when the value should come from a trigger, prior node, or reusable workflow prop.