The upto Method and for loop
# The upto method is a convenience method that does the same thing as a for loop
# The Integer, String, and Date classes all have upto methods
for i in 1..10
print i, " "
end
# => 1 2 3 4 5 6 7 8 9 10
# Compare this with upto, which does exactly the same thing:
1.upto(10) { |i| print i, " " } # => 1 2 3 4 5 6 7 8 9 10
Related examples in the same category