AVADA logo
Published on

How to use for break limit in Shopify

410 words3 min read
  • Name

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 {#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 {#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 {#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.

Exclusive Offer: Shopify Deal for PageFly Audience

Start Your Online Business with Shopify 12 Day Free Trial + Pay Only 1$ For Your First Month