There are a variety iterators that are useful with Ruby such as we’ve already seen in previous samples of code, such as n.times. Others are n.upto and n.downto for going up or down a series of integers and the step, which is more like the traditional loop statement. Their usage would be somewhat like:
3.times {print”X “}
1.upto(3) {[i] print i, ” ” }
99.downto(96) {[i] print i, ” ” }
50.step(70, 5) {[i] print i, ” ” }
Giving you the following results:
X X X 1 2 3 99 98 97 96 50 55 60 65 70
