Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#downto

int.downto(limit) {|i| block } → self
int.downto(limit) → an_enumerator

Iterates the given block, passing in decreasing values from int down to and including limit.

If no block is given, an Enumerator is returned instead.

Example
5.downto(1) { |n| print n, ".. " }
puts "Liftoff!"
#=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
See also #divmod #even? #div #fdiv also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1