9.2 #repeat ... #end repeat

Syntax:

#repeat EXPR
#end repeat

Do something a certain number of times. The argument may be any numeric expression. If it's zero or negative, the loop will execute zero times.

#repeat $times + 3
She loves me, she loves me not.
#repeat
She loves me.

Inside the loop, there's no way to tell which iteration you're on. If you need a counter variable, use #for instead with Python's range function. Since Python's ranges are base 0 by default, there are two ways to start counting at 1. Say we want to count from 1 to 5, and that $count is 5.

#for $i in $range($count)
#set $step = $i + 1
$step.  Counting from 1 to $count.
#end for


#for $i in $range(1, $count + 1)
$i.  Counting from 1 to $count.
#end for

A previous implementation used a local variable $i as the repeat counter. However, this prevented instances of #repeat from being nested. The current implementation does not have this problem as it uses a new local variable for every instance of #repeat.