Bird
0
0

Which method would you use to count down from 5 to 2 in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Loops and Iteration
Which method would you use to count down from 5 to 2 in Ruby?
A5.upto(2)
B2.upto(5)
C5.downto(2)
D2.downto(5)
Step-by-Step Solution
Solution:
  1. Step 1: Identify counting direction

    Counting down means going from a higher number to a lower number.
  2. Step 2: Choose the correct method

    downto counts down from the starting number to the given number, so 5.downto(2) is correct.
  3. Final Answer:

    5.downto(2) -> Option C
  4. Quick Check:

    downto counts down = C [OK]
Quick Trick: Use downto to count down from a number [OK]
Common Mistakes:
MISTAKES
  • Using upto to count down
  • Swapping start and end numbers
  • Confusing method names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes