Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q13 of 15
PowerShell - Control Flow
What will be the output of this PowerShell script?
foreach ($num in 1..3) { Write-Output ($num * 2) }
A2 4 6
B1 2 3
C3 6 9
DError: Invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop range

    The loop runs for numbers 1, 2, and 3.
  2. Step 2: Calculate output for each iteration

    Each number is multiplied by 2, so outputs are 2, 4, and 6.
  3. Final Answer:

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

    1*2=2, 2*2=4, 3*2=6 [OK]
Quick Trick: Multiply each loop number by 2 mentally [OK]
Common Mistakes:
  • Confusing the range operator '..'
  • Thinking output is original numbers
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes