It’s because of variable scope, you should move x definition out:
base_times=14
x=3
base_times.times do |i|
x += 2.50
puts "#{x}"
end
Also there’s syntactic sugar for x = x +
, +=
.
3
solved Add a number through out a loop
It’s because of variable scope, you should move x definition out:
base_times=14
x=3
base_times.times do |i|
x += 2.50
puts "#{x}"
end
Also there’s syntactic sugar for x = x +
, +=
.
3
solved Add a number through out a loop