Bird
0
0

Which of the following is the correct syntax to start an if statement in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Control Flow
Which of the following is the correct syntax to start an if statement in PowerShell?
Aif $x == 5 then { }
Bif ( $x -eq 5 ) { }
Cif $x = 5 { }
Dif $x equals 5 { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell if syntax and verify options

    PowerShell uses if (condition) { code } with -eq for equality check. "if ( $x -eq 5 ) { }" uses correct parentheses, -eq operator, and braces. Others use wrong operators or keywords.
  2. Final Answer:

    if ( $x -eq 5 ) { } -> Option B
  3. Quick Check:

    PowerShell if: parens + -eq = A [OK]
Quick Trick: Use parentheses and -eq for conditions in if [OK]
Common Mistakes:
  • Using == instead of -eq
  • Omitting parentheses
  • Using = for comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes