# Looping (Iterators)

If you ever need to work with a [Lists](https://docs.relay.app/data/lists-arrays) of items in a Relay.app workflow (e.g. a list of email attachments or a list of rows that were found in the spreadsheet), an Iterator is a tool that lets you take an action for each item.

To use an Iterator, you need to do two things:

1. Select the list that you want to iterator over (e.g. the output of a Find step or AI step)
2. Configure the actions that should happen for each item

#### Creating the Iterator

To create an Iterator, select it from the 'Flow Control' menu:

<figure><img src="https://647519108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkKoEy3xMIYaIwd4mRAB%2Fuploads%2Fgit-blob-f2236c09298056cba694bce345c239059a744c33%2FScreenshot%202025-06-22%20at%206.36.05%E2%80%AFAM.png?alt=media" alt=""><figcaption><p>Selecting Iterator in the Flow Control menu.</p></figcaption></figure>

#### Selecting the Items

Once you've added the iterator, the first thing you need to do is to select the list of items, which will typically be the output of one of your previous steps.

<figure><img src="https://647519108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkKoEy3xMIYaIwd4mRAB%2Fuploads%2Fgit-blob-b16c4f82fca10cf467c74c4a290c013fbf038468%2FScreenshot%202025-06-22%20at%206.47.00%E2%80%AFAM.png?alt=media" alt=""><figcaption><p>Selecting the list from my previous step</p></figcaption></figure>

#### \[Optional] Choosing a subset of the List

In most cases, you 'll want to apply the same actions to every element in the list, but in some cases, you'll want to apply the action to a specific subset of items in the list. To do that, change 'Run steps for' to 'A subset of items in the list' and configure your filter criteria.

<figure><img src="https://647519108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkKoEy3xMIYaIwd4mRAB%2Fuploads%2Fgit-blob-aece841b7a6ecf115c5bf628c84119f5dc0b695b%2FScreenshot%202025-06-22%20at%206.47.32%E2%80%AFAM.png?alt=media" alt=""><figcaption><p>Running the Iterator for a subset of items in the list</p></figcaption></figure>

#### Configuring the Actions

Finally, you can set up the actions inside the iterator by pressing the add step button inside the iterator block.

<div align="center"><img src="https://647519108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkKoEy3xMIYaIwd4mRAB%2Fuploads%2Fgit-blob-44e225fc5dd58f61da86c258a8de5fac598b7e87%2FScreenshot%202025-06-22%20at%206.49.22%E2%80%AFAM.png?alt=media" alt=""></div>

Once you add your steps, you'll need to access the data from the current iteration in your automations. To do that, make sure you're selecting a value with the iterator icon.

<figure><img src="https://647519108-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkKoEy3xMIYaIwd4mRAB%2Fuploads%2Fgit-blob-72e564f8020d6dc375f736d549e64be1e901f898%2FScreenshot%202025-06-22%20at%206.52.38%E2%80%AFAM.png?alt=media" alt=""><figcaption><p>Using the email from the current iteration to draft the reply.</p></figcaption></figure>

Once you've added your automations into the iterator block, you're done!

#### Video Demo

Here's a very short video demo of how to set one up.

{% embed url="<https://youtu.be/5j5UNkIKcXs?si=woRVZ_dzRri59yMw>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.relay.app/flow-control/iterators.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
