On Oct 20, 2009, at 12:44 AM, Jian Lin wrote: > Rajinder Yadav wrote: >> Jian Lin wrote: >>> >>> >>> 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 } > > 1. I don't want to create an extra variable. It is a simple loop to > count down 35 times in a short program. > > 2. I want 35.times because it says it is 35 times, very clearly. > 35.downto(1) you will need to think a little how many times it is. > My > purpose is to do it 35 times, so 35.times is best, but I need the > count > down. Something like > > 35.times.countdown do |i| > print i, " " > # do something > end > > -- > Posted via http://www.ruby-forum.com/. > So DO IT that way. Ruby lets you! irb> class Integer def countdown self.downto(1){|i|yield i} end end => nil irb> 35.countdown {|i| print i, ' '}; puts "Boom!" 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Boom! => nil Happy? -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com