From: Brian Candler Date: 2007-05-10T22:00:58+09:00 Subject: Re: loop questions On Thu, May 10, 2007 at 09:33:08PM +0900, Lloyd Linklater wrote: > Which worked as expected. But I had better use for a descending loop. > In pascal it would be > > for i := 5 downto 1 do > writeln('%d', [i]); > > but I could not figure out how to do that in a for loop. I looked > through several books and could not find the answer. Any tips? http://www.rubycentral.com/book/tut_stdtypes.html "Integers also support several useful iterators. We've seen one already---7.times in the code example on page 47. Others include upto and downto, for iterating up and down between two integers, and step, which is more like a traditional for loop. 3.times { print "X " } 1.upto(5) { |i| print i, " " } 99.downto(95) { |i| print i, " " } 50.step(80, 5) { |i| print i, " " } produces: X X X 1 2 3 4 5 99 98 97 96 95 50 55 60 65 70 75 80" (Or better, buy the second edition in paper or PDF form) Regards, Brian.