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

# Looping Engine Suite (For, Repeat, Collect)

> Iterate over collections, execute count-based loops, and collect aggregated pipeline outputs.

The Quixa **Looping Engine** provides first-class nodes for iterating over data structures, polling asynchronous jobs, and aggregating batch results without writing custom iteration loops.

***

## 1. The `For` Node (Collection Iteration)

The **`For`** node loops over an array of items (such as a paginated list of users, order items, or dynamic JSON arrays):

* **Target Array Source**: A dynamic expression referencing an array (e.g. `{{GetOrders.response.body.items}}`).
* **Dual Handles**:
  * **`L` (Loop Body)**: Upper right handle connected to the subgraph executed for every iteration item.
  * **`D` (Done)**: Lower right handle connected to the downstream subgraph executed after all iterations complete.
* **Exposed Loop Context Variables**:
  * `{{forNode.item}}`: The current item in the iteration.
  * `{{forNode.index}}`: The zero-based iteration index (`0, 1, 2...`).
  * `{{forNode.total}}`: Total number of items in the source array.
  * `{{forNode.isFirst}}` / `{{forNode.isLast}}`: Booleans indicating array boundaries.

***

## 2. The `Repeat` Node (Count-Based Loops)

The **`Repeat`** node runs a connected branch a predetermined number of times:

* **Count Expression**: Fixed number or dynamic expression (e.g. `5` or `{{flowVars.maxRetries}}`).
* **Dual Handles**:
  * **`L` (Loop Body)**: Triggered once per count cycle.
  * **`D` (Done)**: Triggered once all repetitions finish.
* **Exposed Variables**:
  * `{{repeatNode.iteration}}`: One-based iteration number (`1, 2, 3...`).
  * `{{repeatNode.index}}`: Zero-based index (`0, 1, 2...`).
  * `{{repeatNode.total}}`: Total repeat target count.

***

## 3. The `Collect` Node (Result Aggregator)

When executing loop bodies, each iteration generates intermediate outputs. The **`Collect`** node gathers these outputs into a single consolidated structure:

* **Collection Mode**:
  * **`Append`**: Aggregates iteration outputs into an array (`[result1, result2, result3]`).
  * **`Merge`**: Merges dictionary objects into a single cohesive payload.
* **Source Expression**: The specific property to gather (e.g. `{{ProcessItem.response.body.status}}`).

***

## Example: Batch Processing Architecture

```mermaid theme={null}
graph LR
    FetchUsers["📥 Fetch Users List"] --> ForEach{"🔁 For-Each User"}
    ForEach -- "L (Body)" --> UpdateUser["✏️ Update User Profile"]
    UpdateUser --> Collect["📦 Collect Results"]
    ForEach -- "D (Done)" --> Finish["🏁 Finalize Batch Summary"]
```

***

## 4. Enterprise Use Case: Batch Processing & Collection

### Scenario

An integration flow queries a list of active accounts, iterates through each account to apply a status update, and aggregates all reference numbers into a final summary report:

1. **`GET /accounts?status=active`**: Returns an array of 5 account objects.
2. **`For` Node**: Iterates over `{{ResponseBinding.GetAccounts.body.items}}`.
3. **Loop Body (`POST /accounts/{id}/hold`)**: Dispatches the update for `{{forNode.item.accountNumber}}`.
4. **`Collect` Node**: Aggregates `{{ResponseBinding.ApplyHold.body.referenceId}}` into an array.
5. **Done Handle (`POST /reports/batch-summary`)**: Dispatches the collected list `{{ResponseBinding.Collect.body.items}}` to the reporting service.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.