Bird
0
0

Which of the following is the correct syntax for a compound case in Swift?

easy📝 Syntax Q12 of 15
Swift - Control Flow

Which of the following is the correct syntax for a compound case in Swift?

switch value {
    case 1, 2, 3:
        print("One to three")
    default:
        print("Other")
}
Acase 1, 2, 3:
Bcase 1; 2; 3:
Ccase (1, 2, 3):
Dcase [1, 2, 3]:
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift compound case syntax

    Swift uses commas to separate multiple values in one case.
  2. Step 2: Check each option

    case 1, 2, 3: uses commas correctly; others use semicolons, parentheses, or brackets incorrectly.
  3. Final Answer:

    case 1, 2, 3: -> Option A
  4. Quick Check:

    Commas separate values in compound case [OK]
Quick Trick: Use commas, not semicolons or brackets, for compound cases [OK]
Common Mistakes:
  • Using semicolons instead of commas
  • Putting values inside parentheses or brackets
  • Missing the colon after case

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes