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:
outerLoop for i in 1...3 {
  for j in 1...3 {
    if j == 2 { break outerLoop }
  }
}
ANo error, code is correct
Bbreak cannot be used inside nested loops
CLoop variable i is not declared
DLabel syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check label syntax

    Label must end with a colon ':' before the loop keyword.
  2. Step 2: Identify the error

    Code uses 'outerLoop for' instead of 'outerLoop: for'.
  3. Final Answer:

    Label syntax is incorrect -> Option D
  4. Quick Check:

    Labels need colon before loop [OK]
Quick Trick: Labels must end with a colon before loop [OK]
Common Mistakes:
  • Omitting colon after label
  • Thinking break can't be used in nested loops
  • Confusing label with variable declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes