# AWL parallel work and loops

Fork/join, multi-step regions, tolerant collection and bounded iteration.

Fork and join combine concurrent work inside a step. Distribute and sequence run multi-step tracks. Loops declare a bound so repetition has an explicit end.

## Forks and regions

- `fork`: Runs work concurrently inside one step: `fork item in items` one branch per item, or a bare `fork` for named branches. Arguments: form: statement; positions: step-body.
- `join`: Closes a `fork`, binding a collection fork's results in input order. Arguments: form: statement; positions: step-body.
- `sequential`: Runs a collection `fork` one item at a time in input order instead of in parallel. Arguments: form: statement; positions: step-body.
- `distribute`: Opens a multi-step region that runs one item track per element in parallel. Arguments: form: statement; positions: step-body.
- `sequence`: Opens a multi-step region that runs one item track at a time in collection order. Arguments: form: statement; positions: step-body.
- `collect`: Closes the nearest region as the first statement of its close step, binding results in input order. Arguments: form: statement; positions: step-body.
- `in`: Names the per-item binding of a fork or a region opener, as in `fork item in items`. Arguments: form: statement; positions: step-body.


A collection fork body compiles as one unbound action or child call. Each named fork branch compiles as one action call. Join collects the declared results.

Per-item distribute tracks are concurrent; sequence tracks run in order. A collected optional result preserves a failed track as an absent value rather than pretending all tracks succeeded.

## Bounded iteration

- `loop`: Runs a bounded value-threading loop whose body runs at least once and must rebind the threaded value. Arguments: form: statement; positions: step-body.
- `counting`: Binds the number of completed iterations of a `loop`. Arguments: form: statement; positions: step-body.
- `until`: States the condition that ends a `loop`, tested after the body has run. Arguments: form: statement; positions: step-body.
- `max`: Bounds iteration: the mandatory ceiling on a `loop`, or `max N visits` on a step inside a flow loop. Arguments: form: statement; positions: step-body.
- `visits`: Completes a step's `max N visits` bound, and reads as the visit count inside that step's guards. Arguments: form: statement; positions: step-body.


A value-threading loop runs its body at least once and must rebind its threaded value. Counting optionally binds completed iterations; until tests after the body, and max is mandatory. A visit bound limits re-entry to a step. Bindings and result routes must remain valid on every path.

Parallel bodies have stricter bytecode compilation rules than sequential bodies. In particular, literal indexing is refused in a parallel branch or per-item track. See [compiler boundaries](/aion/reference/awl/#compiler-boundaries).
