> 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 dynamically by asking a question.

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

```
GET https://learn.mechanic.dev/platform/liquid/basics/control-flow/iteration.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.
