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?
 $count = 1
do {
Write-Output $count
$count++
} while ($count -le 3)
ANo output
B1 2
C2 3
D1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop execution

    The do-while loop runs the body first, printing $count starting at 1, then increments $count.
  2. Step 2: Trace each iteration

    Iteration 1: prints 1, $count becomes 2
    Iteration 2: prints 2, $count becomes 3
    Iteration 3: prints 3, $count becomes 4
    Condition $count -le 3 fails, loop stops.
  3. Final Answer:

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

    Loop prints 1 to 3 [OK]
Quick Trick: Remember do-while runs once before condition check [OK]
Common Mistakes:
  • Thinking loop stops before printing 3
  • Confusing increment timing
  • Assuming no output if condition false initially
  • Mixing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes