Is there a way to break from a foreach loop in velocity?
32,055
The latest version of Velocity (1.6) contains a statement #break
https://velocity.apache.org/engine/1.6.2/user-guide.html#Loops
## list first 5 customers only
#foreach( $customer in $customerList )
#if( $velocityCount > 5 )
#break
#end
$customer.Name
#end
Related videos on Youtube
Author by
barneytron
I'm a C# ASP.NET developer who dreams of making a living doing Ruby and Python instead. Nevertheless, I am rather grateful that I am making a decent living working with em dollar technology.
Updated on July 09, 2022Comments
-
barneytron almost 2 years
I'm looking for a certain condition by using foreach to iterate through a collection (of permissions). So if I find all that I need and don't need to loop anymore, is there a way to break out of the loop? I am new to velocity and trying to grok this weird language.
#foreach ($perm in $space.getPermissions()) #end
-
Nick Jurista over 14 yearsVelocity does not provide a #break, however there are ways to do the same thing:http://mail-archives.apache.org/mod_mbox/velocity-user/200310.mbox/%3C3F85[email protected]%3E
-