title: Liquid control flow tags {% for %} and {% else %}
body: <p>Still new to using liquid in Shopify themes, and documentation is lacking in a few areas, so I'm in "learn as you go" mode, and I'm rebuilding Shopify's Simple theme from scratch as a learning tool. I cam across this bit of code in collection-template.liquid:</p>
  
  <pre><code>1   {% for product in collection.products %}
  2       {% if collection.products.size == 1 %}
  3           &lt;!-- Template Logic --&gt;
  4       {% else %}
  5           &lt;!-- Template Logic --&gt;
  6       {% endif %}
  7           
  8       {% include 'product-grid-item' %}
  9
  10  {% else %} &lt;!-- HANGING ELSE STATEMENT? --&gt;
  11
  12      &lt;!-- Template Logic --&gt;
  13
  14      {% if shop.products_count == 0 and collection.handle == 'all' %}
  15          &lt;!-- Template Logic --&gt;
  16      {% else %}
  17          &lt;!-- Template Logic --&gt;
  18      {% endif %}
  19  {% endfor %}
  </code></pre>
  
  <p>Coming from a Java background, line 10 looks like a compile error. It's an <code>else</code> statement with no opening <code>if</code>.</p>
  
  <p>But, based on context clues, I'm wondering if that <code>{% else %}</code> is like an <code>if (empty)</code>, which would mean the above snippet would be functionally equivalent to:</p>
  
  <pre><code>{% if collection.products.size == 0 %}
      &lt;!-- Line 11-18 from above snippet --&gt;
  {% else %}
      {% for product in collection.products %}
          &lt;!-- Line 2-9 from above snippet --&gt;
      {% endfor %}
  {% endif %}
  </code></pre>
  
  <p>Can someone confirm this?</p>