Hi --

On Sat, 7 Nov 2009, Marnen Laibow-Koser wrote:

> Michael W. Ryder wrote:
> [...]
>> But if you wanted to do something like:
>>    i = 10;
>>    while (i > 0)
>>    {
>>      printf("%d/n", i--);
>>    }
>> in Ruby you would have to do something like:
>>    i = 10
>>    while (i > 0)
>>      puts i
>>      i -= 1
>>    end
>
> No.
>
> 10.downto(1) do |i|
>  puts i
> end
>
>> As far as I can tell there is no way in Ruby to use .each or .times to
>> go backwards.
>
> That's what .downto is for.  (Have you ever needed this?  I have not.)

And in 1.9:

   puts *10.downto(1)

and there's also #reverse_each.


David

-- 
The          Ruby training with D. Black, G. Brown, J.McAnally
Compleat     Jan 22-23, 2010, Tampa, FL
Rubyist      http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)