How do I break out of two loops in liquid. So far I have, which doesn't seem to work for me.
{% for x in a %}
{% for y in b %}
{% if y = 2 %}
{% break %}
// When this loop breaks, the parent for loop should also break
{% endif %}
{% endfor %}
{% endfor %}
You can add a flag and check once that is changed.
{% assign break_loop = false %}
{% for x in a %}
{% for y in b %}
{% if y = 2 %}
{% break %}
{% assign break_loop = true %}
// When this loop breaks, the parent for loop should also break
{% endif %}
{% endfor %}
{% if break_loop %}
{% break %}
{% endif %}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With