# For each

> Runs the steps after it once for each item of a list, one after the other, then goes on after the last.

Source: https://docs.go-lumen.ai/reference/nodes/foreach

## At a glance

| Property | Value |
| --- | --- |
| **Node field** | `forEach` (set instead of `stepRef` on a FlowNode) |
| **Side effects** | no |

A FlowNode sets exactly one of `stepRef`, `branch`, `filter`, `forEach`, `wait` and `approval`.

## Settings

The value of the node field, with these settings.

| Setting | Type | Default | Description |
| --- | --- | --- | --- |
| `items` (required) | string |  | Items is a placeholder naming a list, e.g. `{read-sheet.rows}`. |
| `maxItems` | integer |  | MaxItems is the most items the list may have; the default is 100 and the most that can be asked for is 1000. |
| `end` (required) | string |  | End is the node that closes the loop and runs once after the last item. It is where the body's last node points. |

The full JSON Schema of these settings: [forEach.schema.json](https://docs.go-lumen.ai/schemas/nodes/foreach.schema.json).

## Use it in a flow

```yaml title="flow.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Connector
metadata:
  name: my-email-forward
  namespace: tenant-acme
spec:
  classRef: {name: email-forward}
  config: {}
---
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: foreach-example
  namespace: tenant-acme
spec:
  displayName: "For each"
  triggers:
    - id: start
      ref: {name: email-arrives}
      connectorRef: {name: my-email-forward}
      next: [sheet]
  nodes:
    - id: sheet
      stepRef: {name: read-spreadsheet}
      config: {headerRow: 1}
      next: [rows]
    - id: rows
      forEach: {items: "{sheet.rows}", maxItems: 20, end: done}
      next: [say]
    - id: say
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: "Row {each.index}"
        body: "{each.item}"
      next: [done]
    - id: done
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: "All {rows.count} rows done"
```
