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

# Control Flow

> Use looped agents and dynamic match expressions.

## Agent loops

Use `for ... in` when each item in a collection should be processed with the same agent.

```wire theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
input {
    tasks: [{ id: number, title: string }]
}

agent summarize_each for task in input.tasks {
    model: model.fast
    instruction: "Summarize task {{ task.title }}."

    output {
        task_id: number
        summary: string
    }
}

output {
    summaries: agent.summarize_each
}
```

## Destructuring loop bindings

Loop headers may destructure object-shaped items.

```wire theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
agent summarize_each for { id, title } in input.tasks {
    model: model.fast
    instruction: "Summarize task {{ id }}: {{ title }}."

    output {
        task_id: number
        summary: string
    }
}
```

## Dynamic match

Use `match` when a dynamic value depends on a variant result. Branches must return the same type. For variant declarations, see [Data Types](/syntax/data-types#variants).

```wire theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
dynamic {
    selected_message: match agent.event.kind {
        user_created: agent.event.created_message
        user_deleted: agent.event.deleted_message
        _: agent.event.default_message
    }
}
```

Use `_` as the catch-all branch.
