Challenge - 5 Problems
Until Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of an until loop counting down
What is the output of this Ruby code using an
until loop?Ruby
count = 3 until count == 0 puts count count -= 1 end
Attempts:
2 left
💡 Hint
Remember,
until runs the block while the condition is false.✗ Incorrect
The loop runs while count == 0 is false. It starts at 3 and decreases until it reaches 0, printing 3, 2, and 1.
❓ Predict Output
intermediate2:00remaining
Until loop with break condition inside
What will this Ruby code print?
Ruby
i = 0 until i > 5 puts i break if i == 3 i += 1 end
Attempts:
2 left
💡 Hint
The
break stops the loop early when i is 3.✗ Incorrect
The loop prints i starting at 0. When i reaches 3, the break stops the loop, so it prints 0 to 3.
🔧 Debug
advanced2:00remaining
Identify the error in this until loop
What error does this Ruby code produce?
Ruby
count = 5 until count = 0 puts count count -= 1 end
Attempts:
2 left
💡 Hint
Check the condition in the
until statement carefully.✗ Incorrect
The condition uses = (assignment) instead of == (comparison). This assigns 0 to count every time, so the condition is always false, causing an infinite loop.
🧠 Conceptual
advanced1:30remaining
Understanding until loop condition logic
Which statement best describes how an
until loop works in Ruby?Attempts:
2 left
💡 Hint
Think about the opposite of a
while loop.✗ Incorrect
An until loop runs while its condition is false. It stops when the condition becomes true.
❓ Predict Output
expert2:30remaining
Complex until loop with nested condition
What is the output of this Ruby code?
Ruby
x = 1 until x > 10 if x % 3 == 0 puts x end x += 2 end
Attempts:
2 left
💡 Hint
Check which values of
x are multiples of 3 as it increases by 2.✗ Incorrect
The loop starts at 1 and adds 2 each time: 1, 3, 5, 7, 9. Only 3 and 9 are divisible by 3, so only those print.