for loops

$for{item in items} ... $else ... $rof

Again, the for loop directive behaves like you would expect (like in python) except for additional $else option for the case of an empty sequence (note the difference to python's $else that is executed at end unless loop exited with break statement).

One should note that the statement of the loop must be made up of an iterable on the right side of an in keyword, and whatever is on the left side of the in statement is the loop variable or variables that get set on the evaluation context on each iteration. This may be a single atomic variable, a flat sequence of variables, or even something more complex. Here's an example of a 2-level tuple as left part of a for loop statement:

$prefer{% data={"items":[("Apples", 7), (789, 9), ("Blue", 17)]} %} $if{items}<ul>\ $for{i, (item, code) in enumerate(items)} <li$if{i+1==len(items)} class="last"$fi>${code}:${item}</li> $rof </ul>$fi

That when rendered will produce:

<ul> <li>7:Apples</li> <li>9:789</li> <li class="last">17:Blue</li> </ul>