Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Loops and Iteration
Find the error in this Ruby code:
1.downto(3) { |i| puts i }
AThe block variable is missing
BMissing 'end' keyword for block
Cdownto requires a range, not a number
Ddownto cannot count up; start must be >= end
Step-by-Step Solution
Solution:
  1. Step 1: Understand downto method requirements

    downto counts down from start to end, so start must be greater or equal to end.
  2. Step 2: Check given code

    Here, start is 1 and end is 3, which is counting up, invalid for downto.
  3. Final Answer:

    downto cannot count up; start must be >= end -> Option D
  4. Quick Check:

    downto requires start >= end = A [OK]
Quick Trick: downto counts down only; start must be >= end [OK]
Common Mistakes:
  • Using downto with start < end
  • Forgetting block syntax
  • Confusing block variable usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes