> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiwify.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# Iteration tags

> Iteration tags allow you to repeatedly execute blocks of code.

Iteration tags let you run blocks of code multiple times, which is useful for working with collections and arrays of data.

## `for`

Loops over a collection of items and executes a block of code for each item.

```liquid theme={null}
{% for item in collection %}
  // code to execute for each item
{% endfor %}
```

<ParamField path="item" type="string">
  The name of the variable to assign each item to.
</ParamField>

<ParamField path="collection" type="array">
  The array or collection to iterate over.
</ParamField>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign fruits = "apple,banana,orange" | split: "," %}

    <ul>
    {% for fruit in fruits %}
      <li>{{ fruit }}</li>
    {% endfor %}
    </ul>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <ul>
      <li>apple</li>
      <li>banana</li>
      <li>orange</li>
    </ul>
    ```
  </CodeGroup>
</Columns>

## `else` (for loops)

Executes a block of code if the collection being looped over is empty.

```liquid theme={null}
{% for item in collection %}
  // code to execute for each item
{% else %}
  // code to execute if collection is empty
{% endfor %}
```

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign items = "" | split: "," %}

    <ul>
    {% for item in items %}
      <li>{{ item }}</li>
    {% else %}
      <li>No items found</li>
    {% endfor %}
    </ul>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <ul>
      <li>No items found</li>
    </ul>
    ```
  </CodeGroup>
</Columns>

## `break`

Stops a for loop from continuing to execute.

```liquid theme={null}
{% for item in collection %}
  {% if condition %}
    {% break %}
  {% endif %}
  // code to execute for each item
{% endfor %}
```

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign numbers = "1,2,3,4,5" | split: "," %}

    <ul>
    {% for num in numbers %}
      {% if num == "3" %}
        {% break %}
      {% endif %}
      <li>{{ num }}</li>
    {% endfor %}
    </ul>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <ul>
      <li>1</li>
      <li>2</li>
    </ul>
    ```
  </CodeGroup>
</Columns>

## `continue`

Skips the current iteration of a for loop.

```liquid theme={null}
{% for item in collection %}
  {% if condition %}
    {% continue %}
  {% endif %}
  // code to execute for each item
{% endfor %}
```

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign numbers = "1,2,3,4,5" | split: "," %}

    <ul>
    {% for num in numbers %}
      {% if num == "3" %}
        {% continue %}
      {% endif %}
      <li>{{ num }}</li>
    {% endfor %}
    </ul>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <ul>
      <li>1</li>
      <li>2</li>
      <li>4</li>
      <li>5</li>
    </ul>
    ```
  </CodeGroup>
</Columns>

## `cycle`

Cycles through a set of values and outputs one value each time the tag is processed.

```liquid theme={null}
{% for item in collection %}
  {% cycle value1, value2, value3 %}
{% endfor %}
```

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    <table>
    {% for i in (1..4) %}
      <tr class="{% cycle 'odd', 'even' %}">
        <td>Row {{ i }}</td>
      </tr>
    {% endfor %}
    </table>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <table>
      <tr class="odd">
        <td>Row 1</td>
      </tr>
      <tr class="even">
        <td>Row 2</td>
      </tr>
      <tr class="odd">
        <td>Row 3</td>
      </tr>
      <tr class="even">
        <td>Row 4</td>
      </tr>
    </table>
    ```
  </CodeGroup>
</Columns>

## `tablerow`

Creates a HTML table of items in your collection.

```liquid theme={null}
<table>
{% tablerow item in collection cols:number %}
  // code to execute for each item
{% endtablerow %}
</table>
```

<ParamField path="item" type="string">
  The name of the variable to assign each item to.
</ParamField>

<ParamField path="collection" type="array">
  The array or collection to iterate over.
</ParamField>

<ParamField path="cols" type="number">
  The number of columns in the table.
</ParamField>

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign items = "apple,banana,orange,grape,melon,kiwi" | split: "," %}

    <table>
    {% tablerow item in items cols:2 %}
      {{ item }}
    {% endtablerow %}
    </table>
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    <table>
      <tr>
        <td>apple</td>
        <td>banana</td>
      </tr>
      <tr>
        <td>orange</td>
        <td>grape</td>
      </tr>
      <tr>
        <td>melon</td>
        <td>kiwi</td>
      </tr>
    </table>
    ```
  </CodeGroup>
</Columns>
