Bird
0
0

Find the mistake in this switch code:

medium📝 Debug Q7 of 15
PowerShell - Control Flow
Find the mistake in this switch code:
switch ($val) {
  1: { 'One' }
  2: { 'Two' }
}
AUsing colons instead of braces for cases
BMissing parentheses around $val
CNo default case provided
DUsing numbers instead of strings
Step-by-Step Solution
Solution:
  1. Step 1: Check case syntax

    PowerShell switch cases use braces { }, not colons :.
  2. Step 2: Verify other syntax

    Parentheses are present, default case is optional, and numbers as cases are valid.
  3. Final Answer:

    Using colons instead of braces for cases -> Option A
  4. Quick Check:

    Cases require braces, not colons [OK]
Quick Trick: Use braces for case blocks, not colons [OK]
Common Mistakes:
  • Replacing braces with colons
  • Omitting parentheses
  • Thinking default is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes