Bird
0
0

What will this PowerShell for loop output?

medium📝 Command Output Q5 of 15
PowerShell - Control Flow

What will this PowerShell for loop output?

for ($i=5; $i -gt 2; $i--) { Write-Output $i }
A2 3 4 5
B5 4 3
C5 4 3 2
D3 4 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop start and condition

    Loop starts at 5 and runs while $i is greater than 2, decreasing each time.
  2. Step 2: List output values

    Outputs 5, 4, 3; stops before $i reaches 2.
  3. Final Answer:

    5 4 3 -> Option B
  4. Quick Check:

    Loop counts down from 5 to 3 [OK]
Quick Trick: Decrement loops run while condition true [OK]
Common Mistakes:
  • Including 2 in output
  • Counting up instead of down
  • Outputting in wrong order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes