x.times do |i|
something(i+1)
end
You can perform a simple each
loop on the range from 1 to `x´:
(1..x).each do |i|
#...
end
Try Below Simple Ruby Magics :)
(1..x).each { |n| puts n }
x.times { |n| puts n }
1.upto(x) { |n| print n }
for i in 0..max
puts "Value of local variable is #{i}"
end
Source: Stackoverflow.com