# Filter Early, Assign Once

Avoid complex logic inside loops. Filter and assign before iterating.

```liquid
{% comment %} BAD: complex logic in every iteration {% endcomment %}
{% for product in collection.products %}
  {% if product.available and product.price > 0 and product.tags contains 'featured' %}
    ...
  {% endif %}
{% endfor %}

{% comment %} GOOD: filter early, iterate lean {% endcomment %}
{% assign featured = collection.products | where: 'available', true %}
{% for product in featured limit: 8 %}
  ...
{% endfor %}
```
