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#times

int.times {|i| block } → self
int.times → an_enumerator

Iterates the given block int times, passing in values from zero to int - 1.

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

Example
5.times {|i| print i, " " }   #=> 0 1 2 3 4
See also #succ #to_bn #size #to_d also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1