Complete the code to run the loop until the counter reaches 5.
counter = 0 until counter [1] 5 puts counter counter += 1 end
< makes the loop not run at all.== stops the loop too early or infinite.The until loop runs until the condition becomes true. Using >= means the loop stops when counter is 5 or more.
Complete the code to print numbers from 1 to 3 using an until loop.
num = 1 until num [1] 3 puts num num += 1 end
< or <= makes the loop not run.== causes an infinite loop.The loop runs until num > 3, so it prints 1, 2, and 3.
Fix the error in the until loop condition to avoid an infinite loop.
count = 10 until count [1] 1 puts count count -= 1 end
> causes the loop not to run.== may cause infinite loop or skip values.The loop runs until count < 1, which prevents an infinite loop and prints 10 down to 1.
Fill both blanks to create a loop that counts down from 3 to 1.
i = 3 until i [1] 1 puts i i [2] 1 end
> in the condition causes the loop not to run.+= increases the counter, causing an infinite loop.The loop runs until i < 1, printing 3, 2, 1. i -= 1 decreases i by 1 each time.
Fill all three blanks to create a loop that prints even numbers from 2 to 6.
num = 2 until num [1] 7 if num [2] 2 == 0 puts num end num [3] 2 end
< in the loop condition stops the loop immediately.-= decreases num causing infinite loop or wrong numbers.The loop runs until num > 7. The % operator checks if num is even, and num += 2 increases num by 2 each time. Prints 2, 4, 6.