What is the difference between 'nav' and 'for' for looping? I am new to craftcms and did a look through on the documentation just recently.

I am at the part where it explain about the Categories Field and found out that we can loop through the ElementCriteriaModel with the 'nav' keyword instead of 'for'.

I checked the twig documentation but there are no 'nav' keyword :|

So which one should I use?
for is part of the native Twig language.

for is for general usage... It's the basic, general looping structure that you'll use 99% of the time. You'll find that it closely mirrors for and foreach in other programming languages.



nav is defined by Craft, and doesn't exist natively in Twig.

nav is special... You'll only need it to loop through entries in a Structure section, or categories in a Category Group. The sole purpose of nav is to make it easier to create a menu or navigation.

One of the biggest benefits to using the nav tag is that you'll then be able to use ifchildren within it...

{% ifchildren %}
    &lt;ul&gt;
        {% children %}
    &lt;/ul&gt;
{% endifchildren %}


The logical relationship between nav and its respective children is slightly complicated... and worthy of a separate post if you need further clarification. :)