[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

for loop decrementing ?

pere.noel

7/8/2006 11:58:00 AM

the incrementing for loop :

for i in 0..100
p i
end

gets 0 ...> 100

is their a syntax for a decrementing one like :

for i in 100..0 (specifing the step to -1)
p i
end

--
une bévue
2 Answers

jogloran

7/8/2006 12:06:00 PM

0

100.downto(0) { |i|
p i
}

On 7/8/06, Une bévue <pere.noel@laponie.com.invalid> wrote:
> the incrementing for loop :
>
> for i in 0..100
> p i
> end
>
> gets 0 ...> 100
>
> is their a syntax for a decrementing one like :
>
> for i in 100..0 (specifing the step to -1)
> p i
> end
>
> --
> une bévue
>
>

pere.noel

7/8/2006 2:07:00 PM

0

jogloran <jogloran@gmail.com> wrote:

> 100.downto(0) { |i|
> p i
> }

thanks a lot !!!
--
une bévue