velocity: do something except in last loop iteration

flybywire picture flybywire · Nov 19, 2011 · Viewed 15.3k times · Source

In velocity, I want to do something different in the last loop.

What is the correct idiom?

RELATED: Last iteration of enhanced for loop in java

Answer

soulcheck picture soulcheck · Nov 19, 2011

You can use a test if you are in last iteration::

#foreach( $item in $list )
    $item.text #if( $foreach.hasNext ), #end
#end