Bird
0
0

Which of the following is the correct syntax to create a half-open range from 0 to 9 in Swift?

easy📝 Syntax Q12 of 15
Swift - Operators and Expressions
Which of the following is the correct syntax to create a half-open range from 0 to 9 in Swift?
A0...9
B0..<10
C0..9
D0...10
Step-by-Step Solution
Solution:
  1. Step 1: Identify half-open range syntax

    The half-open range operator in Swift is ..<, which includes the start but excludes the end.
  2. Step 2: Apply to the range 0 to 9

    To include numbers 0 through 9, use 0..<10 because 10 is excluded.
  3. Final Answer:

    0..<10 -> Option B
  4. Quick Check:

    ..< excludes end [OK]
Quick Trick: Use ..< to exclude the last number in range [OK]
Common Mistakes:
  • Using ... when half-open range is needed
  • Writing 0..9 which is invalid syntax
  • Confusing end number inclusion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes