To whom it may concern,

just_me wrote:
> I need to do a for loop, but foreach isn't exactly what I need... Is
> there a way to do an equivalent to for(i=0;i<n;i++). I do not know n - it is
> a variable. I tried #foreach ($i in [1..$n]), but it's not right.

This technique should work. I use Velocity 1.4 and I use this code in
many places in my code:

#foreach ($index in [$itemStart .. $itemEnd])

Perhaps you need to put spaces between the ".." and the references. I've
found that Velocity's parser is sometimes very finicky about whitespace.

Try:

#foreach($i in [1 .. $n])

and see if that works. Also, check the value of $n to make sure it's
what you think it is ;)

-chris

Attachment: signature.asc
Description: OpenPGP digital signature

  • for loop just_me
    • Re: for loop Christopher Schultz

Reply via email to