Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Loops and Iteration
Find the error in this Ruby code snippet:
count = 1
until count > 3
  puts count
  count = count + 1
end
ANo error; code runs and prints 1 to 3
BIncorrect increment syntax; should use 'count += 1'
CInfinite loop because condition never changes
DMissing 'do' keyword after until condition
Step-by-Step Solution
Solution:
  1. Step 1: Check until loop syntax

    In Ruby, the 'do' keyword after the condition in an until loop is optional for multi-line loops.
  2. Step 2: Verify increment and loop logic

    Increment syntax is valid; condition changes correctly, so no infinite loop.
  3. Final Answer:

    No error; code runs and prints 1 to 3 -> Option A
  4. Quick Check:

    Until loop syntax allows omission of 'do' = C [OK]
Quick Trick: The 'do' keyword is optional in multi-line until loops [OK]
Common Mistakes:
MISTAKES
  • Omitting 'do' keyword thinking it's mandatory
  • Assuming increment syntax is wrong
  • Confusing syntax with other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes