velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob.mcl...@verizon.com
Subject Re: problem with #foreach
Date Wed, 07 May 2003 18:16:00 GMT

Terry,

You are right about the syntax.  I actually calculated $foo.size() -1 and
assigned it to a variable.  But try this:
#foreach ($i in [ 0 .. -1] )
      $i
#end

The output:
      0 -1

Rob


                                                                                         
                                
                      "Terry Steichen"                                                   
                                
                      <terry@net-frame.        To:       "Velocity Users List" <velocity-user@jakarta.apache.org>
        
                      com>                     cc:                                    
                                   
                                               Subject:  Re: problem with #foreach       
                                
                      05/07/03 01:47 PM                                                  
                                
                      Please respond to                                                  
                                
                      "Velocity Users                                                    
                                
                      List"                                                              
                                
                                                                                         
                                
                                                                                         
                                




Rob,

I believe you have to do something like this:
#set($x = $foo.size() -1)
#foreach($i in [0..$x])

or,

#set($x = $foo.size()-1)
#set($y = [0..$x])
#foreach($i in $y)

In other words, you can't do arithmetic in the assignment step - you have
to
separate it out.  I think.

HTH,

Terry

----- Original Message -----
From: <rob.mclain@verizon.com>
To: <velocity-user@jakarta.apache.org>
Sent: Wednesday, May 07, 2003 1:29 PM
Subject: problem with #foreach


> I encountered a #foreach in a template that was like a for loop:
>       #foreach ($i in [0 .. $foo.size() -  1 ] )
>
> The problem is when foo.size() == 0, I would expect that the loop would
> fall through since 0 > -1.
> However, it went into a loop, causing a Velocity exception (trying to do
a
> .get()).  Is this a known bug?
>
> Regards,
> Rob
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>


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








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


Mime
View raw message