Bird
0
0

What will this PowerShell code output?

medium📝 Command Output Q13 of 15
PowerShell - Control Flow
What will this PowerShell code output?
 $num = 7
if ($num -lt 5) {
'Less than 5'
} elseif ($num -eq 7) {
'Equal to 7'
} else {
'Other'
}
AEqual to 7
BNo output
COther
DLess than 5
Step-by-Step Solution
Solution:
  1. Step 1: Trace code execution step-by-step

    $num is 7, ($num -lt 5) is false. ($num -eq 7) is true, outputs 'Equal to 7'.
  2. Final Answer:

    Equal to 7 -> Option A
  3. Quick Check:

    7 -eq 7 triggers elseif = D [OK]
Quick Trick: Check conditions top to bottom, first true runs [OK]
Common Mistakes:
  • Choosing first if block without checking condition
  • Ignoring elseif block
  • Assuming else runs always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes