# Loop

<figure><img src="https://3864624312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdo1pkMnofwxf3lpWftw%2Fuploads%2F3Cfw4QCKwcGCv38iNQfJ%2Fimage.png?alt=media&#x26;token=98498c3f-ad45-407d-8712-dee955c023b1" alt=""><figcaption></figcaption></figure>

## Description <a href="#description" id="description"></a>

**What it does:** The **Loop** node iterates over each item in an array and allows you to perform actions on each item individually. It acts like a **"for-each" loop**, repeating a specific section of your flow for every element in the list. All nested nodes inside the loop will run once per item.

**When to use it?** Use the **Loop** node when you need to apply the same logic or action to multiple items — such as sending emails to a list of users, transforming each object in an array, or posting data for every row in a spreadsheet. It’s essential when your automation involves batch processing or repeated steps based on a list of data.

## Component settings <a href="#description" id="description"></a>

The "Loop" node always includes 2 nodes:

* Loop Over Items
* Loop Output

1. **Loop Over Items**

<figure><img src="https://3864624312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdo1pkMnofwxf3lpWftw%2Fuploads%2FQVl1DSgFVUl75r8WgAYH%2Fimage.png?alt=media&#x26;token=7287e8a4-bf2b-4ed5-b9b4-505745d1c264" alt=""><figcaption></figcaption></figure>

| Parameter Name             | Description                                                                                                                                                                                                                                 |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Input                      | <p>A JSON-formatted string that serves as the list of items to iterate over.<br><br><em><mark style="color:red;">Caution: Loop node supports up to 100 runs per session. If the data exceeds 100, it stops at the 100th run</mark></em></p> |
| Batch size                 | Number of items to process in each loop iteration (default is 1).                                                                                                                                                                           |
| On Error when running loop | <p>Defines error-handling behavior, choose between:<br>- Skip and record error (default)<br>- Stop workflow</p>                                                                                                                             |

2. **Loop Output**

<figure><img src="https://3864624312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdo1pkMnofwxf3lpWftw%2Fuploads%2Fp4qu4dZgg5K5eLXynsxz%2Fimage.png?alt=media&#x26;token=b19fa396-7759-49f5-8873-8146be7bc644" alt=""><figcaption></figcaption></figure>

| Parameter Name | Description                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------------- |
| Data to store  | Select the variable or value to store from each loop iteration. The final output will be an array of these results. |

## Advance configurations <a href="#description" id="description"></a>

The Loop component has no advanced configurations.

## How it works <a href="#description" id="description"></a>

The **Loop** structure consists of two primary nodes: **Loop Over Items** and **Loop Output**.

* **Loop Over Items** is the starting point of the loop. It takes a JSON-formatted string as input, where each element in the array represents an item that will be processed one at a time. This node controls how many times the loop will run based on the number of items in the input.
  * *<mark style="color:red;">Caution: Loop node supports up to 100 runs per session. If data exceeds 100, it stops at the 100th run</mark>*
* Between the **Loop Over Items** and **Loop Output**, users can insert any processing nodes needed to handle the repeated logic, such as scraping content from websites, formatting JSON, calling AI models, or sending emails. <mark style="color:red;">Note that branching nodes (e.g.,</mark> <mark style="color:red;"></mark><mark style="color:red;">`Branch`</mark> <mark style="color:red;"></mark><mark style="color:red;">) are</mark> <mark style="color:red;"></mark><mark style="color:red;">**not supported**</mark> <mark style="color:red;"></mark><mark style="color:red;">within a loop.</mark>
* The **Loop Output** node acts as the endpoint of the loop. In this node, you define which data from within the loop should be collected and returned after the loop completes. It allows referencing any node placed between **Loop Over Items** and **Loop Output**. Once selected, those outputs will be aggregated and shown in the **Preview** of the **Loop Output** node.

## Example Flow <a href="#description" id="description"></a>

In the example shown above:

1. The **Trigger** node passes a list of article URLs in JSON format.

<mark style="color:blue;">\[</mark>\ <mark style="color:blue;">{ "url": "<https://www.theverge.com/2024/4/23/24078670/apple-may-product-event-ipad-date>" },</mark>\ <mark style="color:blue;">{ "url": "<https://www.theverge.com/2024/4/23/24078670/apple-may-product-event-ipad-date>" }</mark>\ <mark style="color:blue;">]</mark>

2. The **Loop Over Items** node iterates through each URL.
3. Inside the loop:
   * The **JSON Formatter** prepares the data structure.
   * The **Web Scraper** extracts the content from the given URL.
4. The **Loop Output** node is configured to store both the formatted URL and the scraped content.
5. The final **Output** node then shows the results of the looped operations in a structured format.

This structure allows you to repeat a defined sequence of operations over a list of inputs and collect the results in a single output for further use.

<figure><img src="https://3864624312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdo1pkMnofwxf3lpWftw%2Fuploads%2FXdmy46oaVp5LGa1FTUid%2Fimage.png?alt=media&#x26;token=4c6a728f-3edb-4b10-bb2a-a5a6055faf3f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3864624312-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRdo1pkMnofwxf3lpWftw%2Fuploads%2Ff9kbRvnlvvxr4G4bm58N%2Fimage.png?alt=media&#x26;token=a28c0670-9a1e-4709-a996-7e952cd98309" alt=""><figcaption></figcaption></figure>
