Shopify/liquid — pull request #140 by binarycleric (2012-08-21 18:18:39+00:00)
Title: Added break and continue statements

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.

## Example

Break out of the loop entirely.

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

Stop processing this iteration, but keep the loop going.

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

## Implementation

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).