Bird
0
0

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

easy📝 Syntax Q3 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 the variable in parentheses after 'switch' and code block in braces.
  2. Step 2: Compare options

    Only switch ($variable) { ... } correctly uses 'switch ($variable) { ... }' syntax.
  3. Final Answer:

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

    Correct switch syntax = switch (variable) { } [OK]
Quick Trick: Use parentheses around variable in switch [OK]
Common Mistakes:
  • Omitting parentheses around variable
  • Adding 'then' keyword incorrectly
  • Placing variable outside braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes