Bird
0
0

Find the error in this Swift switch statement:

medium📝 Debug Q14 of 15
Swift - Control Flow

Find the error in this Swift switch statement:

let number = 3
switch number {
case 1, 2
    print("One or Two")
case 3:
    print("Three")
default:
    print("Other")
}
AMissing colon after <code>case 1, 2</code>
BMissing default case
CCannot use compound cases with integers
DMissing parentheses around 1, 2
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of each case

    Each case must end with a colon (:). The first case is missing it.
  2. Step 2: Verify other parts

    Default case is present; compound cases with integers are allowed; parentheses are not needed.
  3. Final Answer:

    Missing colon after case 1, 2 -> Option A
  4. Quick Check:

    Case lines must end with colon [OK]
Quick Trick: Look for missing colons after case labels [OK]
Common Mistakes:
  • Forgetting colon after case
  • Thinking parentheses are required
  • Believing compound cases disallow integers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes