New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added break and continue statements #140

merged 2 commits into from Aug 21, 2012


None yet
3 participants

binarycleric commented Aug 21, 2012

At my day job we've been using Liquid to allow clients to customize the look and feel of our product. While doing various client implementations I noticed that statements like break and continue were missing from the language's vocabulary.

If this isn't a feature Shopify want's to see included with Liquid I totally understand, I just figured I would share some of my work.


Break out of the loop entirely.

{% for item in collection %}
  {% if item.condition %}
    {% break %}
  {% endif %}
{% endfor %}

Stop processing this iteration, but keep the loop going.

{% for item in collection %}
  {% if item.other_condition %}
    {% continue %}
  {% endif %}
{% endfor %}


These statements are implemented by pushing and popping an Interrupt object to the context. When an Interrupt has been pushed to the stack Block#render_all will break execution until the Interrupt is handled (only by For#render for now).

binarycleric added some commits Aug 21, 2012

added interrupt class for continue/break statements
When a continue or break statement is executed it pushes an interrupt to a
stack in context. If any non-handled interrupts are present blocks will cease
to execute. The for loop can handle the most recent interrupt in the stack.

This comment has been minimized.


nickpearson commented Aug 21, 2012

+1 for these new break and continue tags.

ssoroka added a commit that referenced this pull request Aug 21, 2012

Merge pull request #140 from binarycleric/feature/break_for_loop
Added break and continue statements

@ssoroka ssoroka merged commit 661ff2c into Shopify:master Aug 21, 2012


This comment has been minimized.


ssoroka commented Aug 21, 2012

❤️ lgtm. merged.

@binarycleric binarycleric deleted the binarycleric:feature/break_for_loop branch Aug 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment