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

# For Loop

**Execute a set of actions for a predefined number of times.**

<img src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/for-loop-flow-control-header.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=ad138b24c5b1a7161bf0b557a5fcd5e8" alt="for-loop-control-header" width="2431" height="1356" data-path="images/for-loop-flow-control-header.webp" />

## Overview

The For Loop action allows you to execute a set of actions repeatedly for a specified number of times or over a collection of items. This action is useful for iterating over a collection of data or performing a set of actions a specific number of times.

### Accessing Action Output within a Loop

When you use actions inside a For Loop, each action's output can be accessed as if it were an array. This feature allows you to retrieve data from any specific iteration of the loop.

To access the output of an action in a specific iteration, use the following syntax:

* For a fixed iteration (e.g., the first iteration): `{{$action.actionName[0].outputField}}`
* For the last iteration: `{{$action.actionName[-1].outputField}}`

Here, `actionName` is the name of the action, and `outputField` is the specific field in the output you want to access. The index `0` refers to the first iteration, `1` for the second, and so on. The index `-1` always refers to the last iteration.

Learn more about this syntax and indexing variables in our [Variables Documentation](/variables/overview).

### Example

<img width="450" src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/for-loop-example.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=0e7ea7f90a93491255945699c22ae905" data-path="images/for-loop-example.webp" />

### Output

```json theme={null}
{
  "$action['Count-to-Ten']: {
    "i": 9 // Last run iteration of the loop
  }
}
```
