Bird
0
0

What will this PowerShell code output?

medium📝 Predict Output Q5 of 15
PowerShell - Operators
What will this PowerShell code output?
$a = 7
if ($a -ne 7) { 'No' } else { 'Yes' }
ANo
BYes
C7
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition $a -ne 7

    $a is 7, so $a -ne 7 means 7 not equal to 7, which is false.
  2. Step 2: Determine which block runs

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

    Yes -> Option B
  4. Quick Check:

    7 -ne 7 is false, so output is 'Yes' [OK]
Quick Trick: -ne means not equal; false runs else block [OK]
Common Mistakes:
  • Thinking -ne means equal
  • Expecting 'No' output
  • Confusing else block behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes