infinite loop in ruby
i = 0
loop do
puts "The value of i is #{i}"
i += 1
end
Explanation:
1. Initialize a variable i
with the value 0.
2. Start an infinite loop using the loop do
construct.
3. Inside the loop, output the value of i
using puts
.
4. Increment the value of i
by 1 using i += 1
.
5. The loop will continue indefinitely, repeatedly outputting the value of i
and incrementing it by 1 in each iteration.