Ruby – Looping through numbers tips and tricks

Here we have a number of handy integer (fixnum) class methods:

irb(main):012:0> 5.upto(10) {|number| puts number}
5
6
7
8
9
10
=> 5
irb(main):013:0> 5.downto(1) {|number| puts number}
5
4
3
2
1
=> 5
irb(main):014:0> 4.times { puts "hello"}
hello
hello
hello
hello
=> 4
irb(main):015:0> 2.step(15,3) {|i| puts i}
2
5
8
11
14
=> 2
irb(main):016:0>