From: Rajinder Yadav Date: 2009-10-20T13:29:06+09:00 Subject: Re: can 35.times do |i| be decrement of "i" ? Jian Lin wrote: > if there is a loop > > 35.times do |i| > print i > # do something here... > end > > it is nice except i hope to count down the "i"... > > it can be > > print 35 - i > > but then if the number needs to be 36 then i need to change both places. > > or it can be > > 35.downto(1) do |i| > > but doing so feel like needing to do some counting... 1 to 35 is in fact > 35 times... so that's good > > if 35.times can go decrement that would be nice too. > > thanks. Not sure I follow what you're asking, or why downto is not a good solution? but you could try this: irb(main):008:0> count=5 irb(main):009:0> count.times { |n| puts count-n } 5 4 3 2 1 => 5 -- Kind Regards, Rajinder Yadav http://DevMentor.org Do Good ~ Share Freely