Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Loops and Iteration
Identify the error in this Ruby code:
i = 1
while i < 5
  puts i
  i = i + 1
ACondition should use <= instead of <
BIncorrect increment syntax
CMissing <code>end</code> to close the while loop
Dputs should be outside the loop
Step-by-Step Solution
Solution:
  1. Step 1: Check loop syntax completeness

    The while loop must be closed with an end keyword in Ruby.
  2. Step 2: Identify missing end

    The code snippet lacks the end to close the loop, causing a syntax error.
  3. Final Answer:

    Missing end to close the while loop -> Option C
  4. Quick Check:

    Ruby loops require end [OK]
Quick Trick: Always close loops with 'end' in Ruby [OK]
Common Mistakes:
MISTAKES
  • Forgetting 'end'
  • Wrong increment syntax
  • Misplacing puts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes