You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Parul Sheth <pa...@yahoo.com> on 2002/07/18 14:34:40 UTC

Break Statement

Please answer this as soon as possible: how do i break from a loop / return from a macro based on some condition

Please have a look at this code

#macro ( countTabbedSection $position )
position = $position
#set ($loopend = $alSections.size() - 1)
#foreach ($count in [$position..$loopend])
 #set( $sectiondataobject = $alSections.get($count) )
 #if ($sectiondataobject.getIsTabbed()==1)
 sectiondataobject.getIsTabbed() = $sectiondataobject.getIsTabbed()
 #else
  ## i want to break this loop here
 #end
#end
#end ## end of macro


#set( $count = 0 )
#foreach ($sectiondataobject in $alSections)
 #countTabbedSection( $count )
 #set( $count=$count+1 )
#end

 

Thanks



---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

Re: Break Statement

Posted by Anakreon Mejdi <am...@ertonline.gr>.
break and continue would be useful though.
It would be nice if Velocity supported those statements.

Geir Magnusson Jr. wrote:

> On 7/18/02 8:34 AM, "Parul Sheth" <pa...@yahoo.com> wrote:
> 
> 
>>Please answer this as soon as possible: how do i break from a loop / return
>>from a macro based on some condition
>>
>>Please have a look at this code
>>
>>#macro ( countTabbedSection $position )
>>position = $position
>>#set ($loopend = $alSections.size() - 1)
>>#foreach ($count in [$position..$loopend])
>>#set( $sectiondataobject = $alSections.get($count) )
>>#if ($sectiondataobject.getIsTabbed()==1)
>>sectiondataobject.getIsTabbed() = $sectiondataobject.getIsTabbed()
>>#else
>>## i want to break this loop here
>>#end
>>#end
>>#end ## end of macro
>>
>>
>>#set( $count = 0 )
>>#foreach ($sectiondataobject in $alSections)
>>#countTabbedSection( $count )
>>#set( $count=$count+1 )
>>#end
>>
>>
> 
> We have no break statement.  Generally, people do this with some kind of
> $running flag and an #if()
> 
> I've am implementing a break; in another project, and will report back on
> how well it works.
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Break Statement

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 7/18/02 8:34 AM, "Parul Sheth" <pa...@yahoo.com> wrote:

> 
> Please answer this as soon as possible: how do i break from a loop / return
> from a macro based on some condition
> 
> Please have a look at this code
> 
> #macro ( countTabbedSection $position )
> position = $position
> #set ($loopend = $alSections.size() - 1)
> #foreach ($count in [$position..$loopend])
> #set( $sectiondataobject = $alSections.get($count) )
> #if ($sectiondataobject.getIsTabbed()==1)
> sectiondataobject.getIsTabbed() = $sectiondataobject.getIsTabbed()
> #else
> ## i want to break this loop here
> #end
> #end
> #end ## end of macro
> 
> 
> #set( $count = 0 )
> #foreach ($sectiondataobject in $alSections)
> #countTabbedSection( $count )
> #set( $count=$count+1 )
> #end
> 

We have no break statement.  Generally, people do this with some kind of
$running flag and an #if()

I've am implementing a break; in another project, and will report back on
how well it works.

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>