Bird
0
0

What is the output of this script?

medium📝 Command Output Q5 of 15
PowerShell - Scripting Best Practices
What is the output of this script?
$count = 3
for ($i=1; $i -le $count; $i++) {
  Write-Output $i
}
A1 2
B3 2 1
C1 2 3
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop range

    The loop runs from 1 to 3 inclusive.
  2. Step 2: Identify output per iteration

    Each iteration outputs the current value of $i.
  3. Final Answer:

    1 2 3 -> Option C
  4. Quick Check:

    For loop outputs 1 to 3 = A [OK]
Quick Trick: For loops run from start to end inclusive [OK]
Common Mistakes:
  • Assuming reverse order output
  • Stopping loop early
  • Expecting no output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes