Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Operators
What will be the output of this PowerShell code?
$x = 5
if ($x -ne 5) { 'No' } else { 'Yes' }
A5
BNo
CYes
DFalse
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition $x -ne 5

    $x is 5, so $x -ne 5 means 5 not equal to 5, which is False.
  2. Step 2: Determine which block runs

    Since condition is False, the else block runs, outputting 'Yes'.
  3. Final Answer:

    Yes -> Option C
  4. Quick Check:

    5 not equal 5 is False, so else runs [OK]
Quick Trick: -ne means not equal; false triggers else block [OK]
Common Mistakes:
  • Thinking -ne means equal
  • Confusing output with variable value
  • Ignoring else block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes