You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2003/10/08 17:44:25 UTC

Re: How can I break a Foreach loop?

theFenix <rg...@xasa.com> wrote:
> Hello:
> 
> I'm a VM programmer and I search for a method to break a loop when I find 
an occurrence in a Vector object.
> 
> Something like the "break" statement in Java and C++ or another way to 
simulate this.
> 
> I hope that you can help me.

I don't think you can break it, but you can choose to ignore the rest of the 
elements.
This is all off the top of my head, so there may be syntax errors.

#set ($loopNotDone = "true")
#foreach $aValue in $aList

#if ("$loopNotDone" = "true")

## your code here

## detect end condition -- equivalent to break
#if (end condition)
#set ($loopNotDone = "false")
#end ##if (end condition)

## more of your code here


#end ## if $loopNotDone

#end ## foreach $aValue


Yeah, those years of programming in assembly can really pay off at times 
like this :-)

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org