Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q4 of 15
Swift - Loops
What will be the output of this Swift code?
for i in 1...5 {
    if i == 3 {
        continue
    }
    print(i)
}
A1 2 3 4 5
B1 2
C3 4 5
D1 2 4 5
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop and condition

    The loop runs from 1 to 5. When i equals 3, continue skips printing 3.
  2. Step 2: Determine printed values

    Numbers 1, 2, 4, and 5 are printed; 3 is skipped.
  3. Final Answer:

    1 2 4 5 -> Option D
  4. Quick Check:

    Continue skips 3, output excludes 3 [OK]
Quick Trick: Continue skips printing 3, so 3 is missing [OK]
Common Mistakes:
  • Including 3 in output
  • Confusing continue with break
  • Assuming loop stops at 3

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes