Bird
0
0

Which of the following is the correct syntax to start a switch statement in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Control Flow
Which of the following is the correct syntax to start a switch statement in PowerShell?
Aswitch ($variable) { ... }
Bswitch $variable { ... }
Cswitch { $variable } ...
Dswitch ($variable) then { ... }
Step-by-Step Solution
Solution:
  1. Step 1: Recall switch syntax

    PowerShell requires parentheses around the value: switch ($variable) { ... }
  2. Step 2: Check other options

    switch $variable { ... } misses parentheses, C has wrong braces, D uses invalid 'then'.
  3. Final Answer:

    switch ($variable) { ... } -> Option A
  4. Quick Check:

    Parentheses around variable = B [OK]
Quick Trick: Always put the variable inside parentheses after switch [OK]
Common Mistakes:
  • Omitting parentheses around the variable
  • Using 'then' keyword incorrectly
  • Wrong brace placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes