Bird
0
0

Identify the problem in this code snippet:

medium📝 Debug Q7 of 15
Ruby - Loops and Iteration
Identify the problem in this code snippet:
10.upto(7) { |i| puts i }
Aupto cannot count down; start must be <= end
BMissing parentheses around block
CBlock variable is not used
DSyntax error due to missing 'end'
Step-by-Step Solution
Solution:
  1. Step 1: Understand upto method behavior

    upto counts up from start to end, so start must be less or equal to end.
  2. Step 2: Analyze the code

    Here, start is 10 and end is 7, which is counting down, invalid for upto.
  3. Final Answer:

    upto cannot count down; start must be <= end -> Option A
  4. Quick Check:

    upto requires start <= end = A [OK]
Quick Trick: upto counts up only; start must be <= end [OK]
Common Mistakes:
MISTAKES
  • Using upto with start > end
  • Ignoring block variable usage
  • Assuming automatic reverse counting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes