Bird
0
0

What does the following Swift code print?

easy📝 Conceptual Q11 of 15
Swift - Loops
What does the following Swift code print?
for i in 1...3 { print(i) }
A1 2
B1 2 3
C0 1 2 3
D2 3 4
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range operator

    The range 1...3 is a closed range including 1, 2, and 3.
  2. Step 2: Loop prints each number in the range

    The loop prints 1, then 2, then 3 on separate lines.
  3. Final Answer:

    1 2 3 -> Option B
  4. Quick Check:

    Closed range includes last number = 1 2 3 [OK]
Quick Trick: Closed range includes last number, so count all numbers [OK]
Common Mistakes:
  • Thinking the last number is excluded
  • Starting from 0 instead of 1
  • Confusing closed and half-open ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes