Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q6 of 15
Swift - Loops
Identify the error in this Swift code snippet:
for i in 1...5 {
    if i == 3 {
        continue()
    }
    print(i)
}
AUsing parentheses with continue causes a syntax error.
BThe loop range is invalid.
CThe print statement is outside the loop.
DNo error; code runs correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of continue statement

    In Swift, continue is a keyword and must not have parentheses.
  2. Step 2: Confirm other parts are correct

    The loop range and print statement are valid and correctly placed.
  3. Final Answer:

    Using parentheses with continue causes a syntax error. -> Option A
  4. Quick Check:

    Continue must not have parentheses [OK]
Quick Trick: Continue is keyword, no parentheses allowed [OK]
Common Mistakes:
  • Adding parentheses after continue
  • Misplacing print statement
  • Incorrect loop range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes