# Foreach

The Foreach action node loops over objects in a [data source](https://docs.appfarm.io/reference/apps/data/data-sources) and runs a block of action nodes for each object.

## Usage

This action node is used to run a block of other action nodes repeatedly. The block will be run once for each object in the data source according to the object selection. On each iteration, the current object becomes the [object in context](https://docs.appfarm.io/reference/platform-concepts/objects#object-in-context).&#x20;

{% hint style="info" %}
**Good to know**

If you want to update or delete a selection of objects use the [Update object](https://docs.appfarm.io/library/action-nodes/update-object) or [Delete objects](https://docs.appfarm.io/library/action-nodes/delete-objects) action nodes.
{% endhint %}

### Example

{% tabs %}
{% tab title="Loop through active projects" %}
Your app has a data source containing all projects. You'd like to iterate over active projects to calculate resource utilization.

Use Foreach to loop over a filtered selection of projects with a filter `Project.State EQUALS Active` to only iterate over active projects.
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Showroom**

A Foreach example is available in our [Showroom](https://showroom.appfarm.app/action-nodes/foreach). You can view the demo, as well as access the setup in Appfarm Create. Don't have access? [Register](https://showroom.appfarm.app/sign-up).
{% endhint %}

## Properties

<table><thead><tr><th width="213">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Data Source</strong></td><td>Select a multi-cardinality data source containing the objects to iterate over.<br><br>You may also select a multi-reference property (an <a href="../../../reference/data-model/object-class-properties#general-properties">Object Class Property with Cardinality <code>Many</code></a>), and iterate over the referenced objects.</td></tr><tr><td><strong>Selection</strong></td><td><p>Define the objects to update.</p><ul><li><code>All objects</code></li><li><a href="../../../reference/platform-concepts/objects#object-selection"><code>Selected object(s)</code></a></li><li><code>Filtered selection</code></li></ul></td></tr><tr><td><strong>Filter</strong></td><td><em>Available when</em> <strong>Selection</strong> <em>is Filtered selection.</em><br><br>Define the <a href="../../reference/platform-concepts/filters">filter</a> to apply to the data source.</td></tr><tr><td><strong>Execution Mode</strong></td><td><strong>Sequential</strong>: The default. All action nodes inside the Foreach loop will be executed in sequence.<br><br><strong>Paralell</strong>: Execute all action nodes inside the Foreach loop in paralell. </td></tr></tbody></table>
