Bird
0
0

What does the Ruby method 5.upto(8) do?

easy📝 Conceptual Q11 of 15
Ruby - Loops and Iteration
What does the Ruby method 5.upto(8) do?
ACounts from 5 down to 8, excluding 8
BCounts from 8 down to 5, including both 8 and 5
CCounts from 5 up to 8, including both 5 and 8
DCounts from 8 up to 5, excluding 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand the upto method

    The upto method counts upwards from the starting number to the ending number, including both.
  2. Step 2: Apply to the example 5.upto(8)

    This means it counts 5, 6, 7, 8 in order.
  3. Final Answer:

    Counts from 5 up to 8, including both 5 and 8 -> Option C
  4. Quick Check:

    upto counts up = A [OK]
Quick Trick: Remember: upto counts up, downto counts down [OK]
Common Mistakes:
  • Confusing upto with downto
  • Thinking it excludes the last number
  • Assuming it counts down instead of up

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes