The @while directive allows for simple loops. For example:
// Calculate 1 + 2 + ... + n
@def int mSum(int n) =
{
@let int sum = 0
@let int i = 1
@while (i <= n)
{
@let sum = sum + i
@let i = i + 1
}
sum
}
@assert( mSum(4) == 10 )
// Generate "1+2+...+n"
@def string mGenerateSum(int n) =
{
@let string sum := 1
@let int i = 2
@while (i <= n)
{
@let sum := sum+i
@let i = i + 1
}
@str(sum)
}
@assert(@str(mGenerateSum(4)) == "1+2+3+4")