Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - Control Flow
What will be the output of this PowerShell code?
$temperature = 15
if ($temperature -gt 30) { 'Very Hot' } elseif ($temperature -ge 20) { 'Hot' } elseif ($temperature -ge 10) { 'Mild' } else { 'Cold' }
A'Cold'
B'Hot'
C'Very Hot'
D'Mild'
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first condition

    Check if $temperature (15) is greater than 30. It's false.
  2. Step 2: Evaluate second condition

    Check if $temperature (15) is greater or equal to 20. It's false.
  3. Step 3: Evaluate third condition

    Check if $temperature (15) is greater or equal to 10. It's true.
  4. Final Answer:

    'Mild' -> Option D
  5. Quick Check:

    15 >= 10 is true, so output is 'Mild' [OK]
Quick Trick: Evaluate conditions top-down; first true condition runs [OK]
Common Mistakes:
  • Assuming conditions are checked in reverse order
  • Confusing greater than and greater or equal operators
  • Ignoring the order of elseif blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes