On this page

$LoopTool is used with the #foreach loops. It wraps a list to let you specify a condition to terminate the loop and reuse the same list in a different loop. The following example shows how to use $LoopTool.

#set( $list = [1..7] )
#set( $others = [3..10] )
#foreach( $item in $loopTool.watch($list).sync($others, 'other') )
$item -> $loopTool.other
#if( $item >= 5 )$loopTool.stop()#end
#end

Output
------
1 -> 3
2 -> 4
3 -> 5
4 -> 6
5 -> 7

$LoopTool.wrap( list )

Wrap a list with the tool.


Name Type Description 
Parameter(s) list java.util.List An array or a
list instance. 
 ReturnLoopTool Return an
LoopTool
instance. 

$<LoopTool instance>.hasMore()

Check if the iteration has more elements.


Name Type Description 
Return boolean Return true if there
are more elements
in the wrapped list. 

$<LoopTool instance>.more()

Ask for the next element in the list.


Name Type Description 
Return  java.lang.Object An element
instance. 

$<LoopTool instance>.remove()

Remove the current element from the list.

$<LoopTool instance>.reset()

Reset the wrapper so that it will start over at the beginning of the list.

$<LoopTool instance>.stop()

Put a condition to break off a loop.

$<LoopTool instance>.toString()

Return an object as a string.