Home > Shopify Development > Liquid Iteration: for break limit

How to use for break limit in Shopify

Sam Nguyen
Sam Updated: August 18, 2024


Drive 20-40% of your revenue with Avada
avada email marketing

Since 2006, Liquid has been used in Shopify as a language template. In Liquid, you use tags consisting of comment, control flow, iteration, raw and variable to show complex content. In this tutorial, we will introduce you about some types of liquid iteration including for, break and limit.

Table of content

Brief guide to Liquid

There are three types in Liquid codes including objects, tags and filters. Liquid use objects to show the location of the content on a page. Double curly braces denote objects and variable names. Filters change a Liquid object’s output. Tags create logic and control flow for a template. Tags begin with two curly braces and percent signs. Tags can be divided into three types: control flow, iteration and variable assignment.

Iteration consists of several typical types that can help you display information on your front page. Today tutorial focuses on for, break and limit iteration.

General information about Liquid iteration

Iteration tags run blocks of codes repeatedly. For tag repeatedly executes a block of code.

How to use for break limit iteration

First of all, for tag repeatedly execute a block of code for a full list of attributes available within a for loop.


 {% for product in collection.products %}
    {{ product.title }}
  {% endfor %}


hat shirt pants

Second, break iteration causes the loop to stop iterating once it encounters this tag.


{% for i in (1..5) %}
  {% if i == 4 %}
    {% break %}
  {% else %}
    {{ i }}
  {% endif %}
{% endfor %}


1 2 3

Third, limit iteration limits the loop to the specified number of iterations. For instance, you have a chain of number and you want to show only two numbers of that chain on your website, then you should do:


<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit:2 %}
  {{ item }}
{% endfor %}


1 2


In conclusion, Liquid provides three iteration tags to you to execute blocks of codes. You can use tags of for, break and limit in order to upload the chain of characters. We hope that the tutorial is helpful, and let us know your difficulties, we will address them.

Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.