Bird
0
0

Which Swift range expression correctly iterates from 1 up to but not including 10 in a for-in loop?

easy📝 Conceptual Q2 of 15
Swift - Loops
Which Swift range expression correctly iterates from 1 up to but not including 10 in a for-in loop?
A1...10
B1..<10
C0..<10
D0...9
Step-by-Step Solution
Solution:
  1. Step 1: Understand range operators

    The operator ..< creates a half-open range excluding the upper bound, while ... includes it.
  2. Step 2: Identify the correct range

    To iterate from 1 up to but not including 10, use 1..<10.
  3. Final Answer:

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

    Range excludes 10, so loop stops before 10 [OK]
Quick Trick: ..< excludes upper bound, ... includes it [OK]
Common Mistakes:
  • Using ... which includes the upper bound
  • Starting range at 0 instead of 1
  • Confusing inclusive and exclusive ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes