Bird
0
0

Which of the following is the correct syntax to match a number n in the range 5 to 15 inside a case statement using pattern matching?

easy📝 Syntax Q12 of 15
Ruby - Control Flow

Which of the following is the correct syntax to match a number n in the range 5 to 15 inside a case statement using pattern matching?

case n
  in ???
    puts "In range"
  else
    puts "Out of range"
end
Ain (5..15)
B5..15
C5...15
Din 5..15
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct pattern syntax in in clause

    Inside case, in is followed directly by the pattern, so in 5..15 is correct syntax.
  2. Step 2: Check other options for syntax errors

    Options without in or with extra parentheses are invalid syntax in this context.
  3. Final Answer:

    in 5..15 -> Option D
  4. Quick Check:

    Use in followed by the pattern without extra keywords or parentheses [OK]
Quick Trick: Use in once, then the pattern without extra keywords [OK]
Common Mistakes:
  • Writing in in 5..15 which is invalid
  • Adding parentheses around the range
  • Using three-dot range 5...15 which excludes 15

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes