> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/platform/liquid/basics/control-flow/iteration.md).

# Iteration

**Iteration** tags control the flow of code, running that code multiple times against successive values in an array.

## for

The `for` tag runs its code against every value found in an array.

```liquid
{% for product in products %}
  {% assign product_tags = product.tags | split: ", " %}
{% endfor %}
```

```liquid
{% assign seconds_per_day = 86400 %}

{% for i in (1..days_ahead) %}
  {% assign time_ahead = 0 | plus: seconds_per_day | times: i %}
{% endfor %}
```

### The forloop object

The `forloop`object contains information about the loop currently being processed. [Learn about its contents from Shopify](https://shopify.dev/docs/themes/liquid/reference/objects/for-loops).

```liquid
{% for tag in tags %}
  {% if forloop.first %}
    {% comment %}
      This is the first tag in the set!
    {% endif %}
  {% endif %}
{% endfor %}
```

## continue

Used within a `for`/`endfor` block, the `continue` tag instructs Liquid to skip the rest of the code in the current pass, and begin again with the next value in the array (if any).

```liquid
{% for fulfillment in order.fulfillments %}
  {% if fulfillment.status == "cancelled" %}
    {% comment %}
      Skip this fulfillment, and process the next one (if any).
    {% endcomment %}
    {% continue %}
  {% endif %}

  {% assign tag_to_add = "not cancelled" %}
{% endfor %}
```

## break

Used within a `for`/`endfor` block, the `break` tag instructs Liquid to skip the rest of the code in the current pass, and to stop processing the array completely.

```liquid
{% assign order_includes_compare_at_pricing = false %}

{% for line_item in order.line_items %}
  {% if line_item.variant.compare_at_price != blank %}
    {% assign order_includes_compare_at_pricing = true %}
    {% comment %}
      Only need to detect this once, so we can now break out of the loop.
    {% endcomment %}
    {% break %}
  {% endif %}
{% endfor %}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/platform/liquid/basics/control-flow/iteration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
