> For the complete documentation index, see [llms.txt](https://docs.getmesa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getmesa.com/tools/loop.md).

# Loop

The **Loop** tool allows you to iterate over a list of items one-by-one.

A Loop is useful when you want to take a list of things, for example, all of the line items in an order, and perform an action on each individual item.

## Configure <a href="#overview" id="overview"></a>

### Loop

To iterate over specific items from a list (typically from the [Trigger](https://docs.getmesa.com/workflow-builder/triggers) or [Actions](https://docs.getmesa.com/apps/shopify/actions)), use the [variables](https://docs.getmesa.com/workflow-builder/fields/variables) menu to select the list of items after adding your Loop step.

<figure><img src="/files/zgBfaCcjWfGmsCz81S9O" alt="Screenshot of MESA workflow builder, added Loop step, open the variables menu to select the list of items to iterate over. Spotlight the list variable selection."><figcaption></figcaption></figure>

After your Loop has been added and configured, you'll see your Loop steps within a confined container with a grey border.

To perform one or more tasks on each item in the list, add [actions](https://docs.getmesa.com/apps/shopify/actions) after the Loop within the container with a grey border.

You can reference the individual items or their information by using the Loop variables that will populate for actions added in the Loop container.

You will have variables available from steps that occur prior to the Loop in your workflow, as well as the Loop variables. Typically, you'll want to use Loop variables when configuring actions within the Loop container.

<figure><img src="/files/hkwg4CKuPBEwQvN3rlN3" alt="Screenshot of MESA workflow builder, action added inside the Loop container with the grey border, using Loop variables. Spotlight the Loop container and its variables."><figcaption></figcaption></figure>

{% hint style="info" %}
Be sure to **Save** your workflow after adding and configuring your Loop to see your available Loop variables.
{% endhint %}

In each Loop action, there are conditions you can add to filter the list.

You can populate the [Filter by conditions](https://docs.getmesa.com/tools/filter#examples) via the More fields button so that specific values or results that meet the conditions are passed to the following steps.

<figure><img src="/files/VYvhpIIGAJQaPesYm3tU" alt="Screenshot of MESA workflow builder, Loop action with the More fields button opened to add Filter by conditions. Spotlight the Filter by conditions fields."><figcaption></figcaption></figure>

## Going Further

### Loop End

The default configuration of the Loop tool will continue the workflow without passing variables after the Loop. However, you can optionally configure a Loop End step to build a list from matching items to use in later steps.

In the Loop step, click the More options button to add the Loop End via the Build a list from matching items checkbox.

<figure><img src="/files/DYOjCpoXhpGXYHZSteMv" alt="Screenshot of MESA workflow builder, Loop step with the More options button opened. Spotlight the Build a list from matching items checkbox that adds the Loop End."><figcaption></figcaption></figure>

After saving your workflow, use the [variable](https://docs.getmesa.com/workflow-builder/fields/variables) selector to append data from the Loop container to use in future steps after the Loop.

The value can be a single variable from an action within the Loop, or you can add a [Transform Mapping](https://docs.getmesa.com/tools/transform#transform-mapping) action within the Loop and map a new object.

<figure><img src="/files/qE33U0gsycHK0lruQK37" alt="Screenshot of MESA workflow builder, Loop End step using the variable selector to append data from the Loop container. Spotlight the variable selector."><figcaption></figcaption></figure>

The variable that's created from the Loop End step will be Loop End > Items, and it can be used in steps after the Loop.

<figure><img src="/files/BBczfTnXn9BfHR9slrDZ" alt="Screenshot of MESA workflow builder, step after the Loop using the Loop End > Items variable. Spotlight the Loop End > Items variable."><figcaption></figcaption></figure>

### Other kinds of Loop steps

Beyond the regular Loop action, you can add different variations of Loop actions to your workflow. These are single-output steps with a different behavior than the Loop & Loop End functionality.

#### Sum

The Loop Sum action will calculate the sum of all items that match a specific criteria.

For example, the Loop Sum action can add up the price of line items (products) in an order and pass that value as a variable to reference in the following steps. The value will be an integer.

<figure><img src="/files/mPW5tMJyhzCpfF2HVJu6" alt="Screenshot of MESA workflow builder, Loop Sum action configured to add up the price of line items in an order. Spotlight the Loop Sum action configuration."><figcaption></figcaption></figure>

#### Map

The Loop Map action will create a list of values that are identified based on the item you're referencing from a previous step.

For example, the Loop Map action can pass all line item (product) titles in an order for tagging purposes.

<figure><img src="/files/lHn6vsnRwbv9DHrMLsOu" alt="Screenshot of MESA workflow builder, Loop Map action configured to create a list of line item titles. Spotlight the Loop Map action configuration."><figcaption></figcaption></figure>

#### Number of Matches

The Loop Number of Matches action will return the number of items that match a specific criteria.

For example, the Loop Number of Matches action can provide an integer as a variable that can be referenced in future steps representing the number of line items (products) in an order with a specific SKU.

<figure><img src="/files/oS9xmlcoqkAo11gThbjh" alt="Screenshot of MESA workflow builder, Loop Number of Matches action configured to return the count of items matching a criteria. Spotlight the Loop Number of Matches action configuration."><figcaption></figcaption></figure>

## Technical Notes

* The Loop queue is synchronous.
* There is a legacy version of the Loop step that can be found on stores with previous versions of MESA, or when using templates that have not been updated to the latest Loop and Loop End functionality.
  * Everything gets enqueued all at once with legacy Loop actions, which makes this action more susceptible to timeouts.
