Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Control Flow

What will be the output of this PowerShell code?

for ($i=1; $i -le 3; $i++) { Write-Output ($i * 2) }
A0 2 4
B1 2 3
C2 4 6
D3 6 9
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop iterations

    The loop runs with $i values 1, 2, and 3 because condition is $i -le 3.
  2. Step 2: Calculate output for each iteration

    Output is $i * 2: 1*2=2, 2*2=4, 3*2=6.
  3. Final Answer:

    2 4 6 -> Option C
  4. Quick Check:

    Multiply each i by 2 = 2 4 6 [OK]
Quick Trick: Multiply loop variable by 2 each iteration [OK]
Common Mistakes:
  • Confusing loop range
  • Multiplying after loop ends
  • Printing loop variable instead of calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes