Advanced Looping in Liquid and Jekyll

Loop over all items in a collection (array or hash):
{% for day in page.days %}
   <li>{{ day }}</li>
{% endfor %}
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
<li>Saturday</li>
<li>Sunday</li>
{% for cat in site.categories %}
   <li>{{ cat[0] }}</li>
{% endfor %}
<li>archives</li>
<li>movies</li>
<li>projects</li>
<li>reboot</li>
<li>how-to</li>
<li>web-dev</li>
Loop over all items in a collection backwards:
{% for day in page.days reversed %}
   <li>{{ day }}</li>
{% endfor %}
<li>Sunday</li>
<li>Saturday</li>
<li>Friday</li>
<li>Thursday</li>
<li>Wednesday</li>
<li>Tuesday</li>
<li>Monday</li>
Loop over a sorted collection:
{% assign sorted_days = (page.days | sort) %}
{% for d in sorted_days  %}
   {{ d }}
{% endfor %}
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
Loop a certain number of times:
{% for i in (0..4) %}
   Iteration {{ i }}
{% endfor %}
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Loop a variable number of times:
{$ assign start = 0 %}
{% assign end = 4 %}
{% for i in (start..end) %}
   Iteration {{ i }}
{% endfor %}
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Loop a certain number of times backwards:
{% for i in (0..4) reversed %}
   Iteration {{ i }}
{% endfor %}
Iteration 4
Iteration 3
Iteration 2
Iteration 1
Iteration 0
Loop over an arbitrary range of integers:
{% for i in (-3..3) %}
Iteration {{ i }}
{% endfor %}
Iteration -3
Iteration -2
Iteration -1
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Loop over the first 5 items in a collection:
{% for day in page.days | limit: 5 %}
{{ day }}
{% endfor %}
Monday
Tuesday
Wednesday
Thursday
Friday
Loop over the first 5 items in a collection in reverse order:
{% for day in page.days reversed limit:5 %}{{ day }}
   <h2>{{ day }}</h2>
{% endfor %}
Friday
Thursday
Wednesday
Tuesday
Monday
Loop over the last 5 items in a collection:
{% assign rev_days = page.days | reverse %}
{% for day in rev_days limit:5 %}{{ day }}
{% endfor %}
Sunday
Saturday
Friday
Thursday
Wednesday
Loop over the last 5 items in a collection:
{% capture start %}
{{ page.days.size | minus:5 }}
{% endcapture %}
{% for day in page.days offset:start %}{{ day }}
{% endfor %}
Wednesday
Thursday
Friday
Saturday
Sunday
Loop over a sorted (descending) collection:
{% assign sorted_days = (page.days | sort | reverse) %}
{% for day in sorted_days  %}{{ month }}
{% endfor %}
Wednesday
Tuesday
Thursday
Sunday
Saturday
Monday
Friday
Do something special on the Nth iteration of the loop:
{% for d in page.days %}
{{ forloop.index }}
{% if forloop.first %}st
{% elsif forloop.index == 2 %}nd
{% elsif forloop.index == 3 %}rd
{% else %}th{% endif %}
 day is {{ d }}
{% endfor %}
1st day is Monday
2nd day is Tuesday
3rd day is Wednesday
4th day is Thursday
5th day is Friday
6th day is Saturday
7th day is Sunday
Use increment outside a loop:
{% increment some_var %}
{% increment some_var %}
{% increment some_var %}
{% increment some_var %}
0
1
2
3
Use increment inside a loop:
{% for i in (0..3) %}
   {% increment some_other_var %}
{% endfor %}
0
1
2
3
Use nested loops:
{% for outer in (0..3) %}
   {% for inner in (0..3) %}
      {{ outer }}:{{ inner }}
   {% endfor %}
{% endfor %}
0:0
0:1
0:2
0:3
1:0
1:1
1:2
1:3
2:0
2:1
2:2
2:3
3:0
3:1
3:2
3:3