Complete the code to create an infinite loop using the loop method.
loop do puts "Hello, world!" [1] end
The next keyword skips to the next iteration, so the loop continues infinitely.
Complete the code to print numbers from 1 to 5 inside an infinite loop, then break the loop.
i = 1 loop do puts i i += 1 [1] end
The break if i > 5 stops the infinite loop after printing numbers 1 to 5.
Fix the error in the code to create an infinite loop that prints 'Looping'.
loop [1] puts 'Looping' end
The correct syntax for an infinite loop using the loop method is loop do.
Fill both blanks to create an infinite loop that prints 'Tick' every second.
loop [1] puts 'Tick' sleep [2] end
The loop do syntax creates an infinite loop, and sleep 1 pauses for one second each iteration.
Fill all three blanks to create an infinite loop that counts from 1 upwards and breaks after 10.
count = [1] loop [2] puts count count += [3] break if count > 10 end
Start counting at 0, use loop do for the infinite loop, and increase count by 1 each time.