Bird
0
0

Which of the following best describes the range used in a Ruby for loop like for i in 1..5?

easy📝 Conceptual Q2 of 15
Ruby - Loops and Iteration
Which of the following best describes the range used in a Ruby for loop like for i in 1..5?
AA list of numbers from 1 to 4
BA list of numbers from 1 to 6
CA list of numbers from 0 to 5
DA list of numbers from 1 to 5 inclusive
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby ranges

    The range 1..5 includes all numbers from 1 up to and including 5.
  2. Step 2: Confirm the range behavior in for loop

    The for loop iterates over each number in the range, including the last number.
  3. Final Answer:

    A list of numbers from 1 to 5 inclusive -> Option D
  4. Quick Check:

    Range 1..5 = inclusive 1 to 5 [OK]
Quick Trick: .. means inclusive range in Ruby [OK]
Common Mistakes:
  • Thinking .. excludes the last number
  • Confusing .. with ...
  • Assuming range starts at 0

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes