0
0
Rubyprogramming~20 mins

Until loop in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Until Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
A
1
2
3
B
0
1
2
3
C
3
2
1
0
D
3
2
1
Attempts:
2 left
💡 Hint
Remember, until runs the block while the condition is false.
Predict Output
intermediate
2: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
A
0
1
2
3
4
5
B
0
1
2
3
C
0
1
2
3
4
D
1
2
3
Attempts:
2 left
💡 Hint
The break stops the loop early when i is 3.
🔧 Debug
advanced
2: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
AInfinite loop
BSyntaxError
CTypeError
DNo error, prints 5 to 1
Attempts:
2 left
💡 Hint
Check the condition in the until statement carefully.
🧠 Conceptual
advanced
1:30remaining
Understanding until loop condition logic
Which statement best describes how an until loop works in Ruby?
AIt runs the loop while the condition is true.
BIt runs the loop until the condition becomes true.
CIt runs the loop while the condition is false.
DIt runs the loop only once regardless of the condition.
Attempts:
2 left
💡 Hint
Think about the opposite of a while loop.
Predict Output
expert
2: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
A
3
6
9
B
3
9
C
3
9
15
D
6
9
Attempts:
2 left
💡 Hint
Check which values of x are multiples of 3 as it increases by 2.