Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q13 of 15
Swift - Control Flow

What will be printed by this Swift code?

let letter = "b"
switch letter {
case "a", "e", "i", "o", "u":
    print("Vowel")
case "b", "c", "d":
    print("Consonant")
default:
    print("Other")
}
AVowel
BNo output
CConsonant
DOther
Step-by-Step Solution
Solution:
  1. Step 1: Identify the value of letter

    The variable letter is "b".
  2. Step 2: Match letter in switch cases

    "b" matches the second case with "b", "c", "d" which prints "Consonant".
  3. Final Answer:

    Consonant -> Option C
  4. Quick Check:

    "b" in second case = Consonant [OK]
Quick Trick: Check which case list contains the value [OK]
Common Mistakes:
  • Confusing vowels and consonants
  • Forgetting to include default case
  • Assuming no output if no exact match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes