> OctoPerf load testing - ForEach Action documentation page. ForEach Actions loops through the values of its input variable and play its children actions for each value.

Source: https://api.octoperf.com/doc/design/edit-virtual-user/action-types/logic-actions/foreach-action/

# ForEach Action

A ForEach Action **loops through the values of its _input variable_**. For each successive value, the _output variable_ is affected and the children actions are executed.
The actions below the ForEach can use the *output variable* in their configuration.

!!! note
    The _input variable_ format is special. You can define a ForEach input in two ways:

    * Create a [Regex Post Processor](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/post-processors/regexp-variable-extractor/) and select "All" as the _match number_. In this case the ForEach children are processed for each extracted value.
    * If your _input variable_ is named `myVar`, create multiple [variables](https://api.octoperf.com/doc/design/edit-virtual-user/configuration/variables/) named:
        * `myVar_1`
        * `myVar_2`
        * `myVar_3`
        * and the _output variable_ consecutively have the values of `myVar_1`, `myVar_2` and `myVar_3`.


Here's an example with a regex called "categories" set to _match number_ "All":
![Foreach Action](https://api.octoperf.com/doc/design/edit-virtual-user/action-types/logic-actions/img/foreach.png "Foreach Action")

!!! tip
    You can <a href="https://api.octoperf.com/doc/design/edit-virtual-user/action-types/logic-actions/img/foreach.jmx" download>download a JMX of this example here</a> and import it in your project using the JMeter project option.

To sum up:

Parameter name | Description | Required
--- | --- | ---
Input Variable Name | Name of the input variable. `${...}` is omitted, e.g. write `myInputVar` and **not** `${myInputVar}` | No
Output Variable Name | Name of the output variable. `${...}` is omitted, e.g. write `myOutputVar` and **not** `${myOutputVar}` | Yes
