upto with / without {} : upto « Statement « Ruby






upto with / without {}

1.upto 3 do |x|
  puts x
end
# 1
# 2
# 3
1.upto(3) { |x| puts x }
# 1
# 2
# 3

 








Related examples in the same category

1.use the upto iterator, which is what traditional for loops translate into in Ruby.
2.Use an upto Iterator to reference array element
3.uses the upto iterator to create a loop similar to a for loop from other languages
4.use curly braces ({}):
5.The upto Method and for loop
6.Example of upto that prints out a times table for 2
7.do all the times tables from 1 to 12
8.One date may upto another
9.Interpolation with upto and array