# Avoid Nested Loops

Nested `for` loops multiply iterations. Flatten with assigns or use Liquid filters.

```liquid
{% comment %} BAD: O(n*m) — 50 products x 10 tags = 500 iterations {% endcomment %}
{% for product in collection.products %}
  {% for tag in product.tags %}
    {% if tag == 'sale' %}
      ...
    {% endif %}
  {% endfor %}
{% endfor %}

{% comment %} GOOD: filter directly {% endcomment %}
{% for product in collection.products %}
  {% if product.tags contains 'sale' %}
    ...
  {% endif %}
{% endfor %}
```
