Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q6 of 15
PowerShell - Control Flow
Identify the error in this PowerShell code:
$count = 0
do
Write-Output $count
$count++
while ($count -lt 3)
ACondition syntax is invalid
BMissing curly braces around do block
CIncorrect increment operator
DVariable $count not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Check do-while syntax

    PowerShell requires curly braces {} to group multiple statements in do block.
  2. Step 2: Identify missing braces

    Code has multiple statements but no braces, causing syntax error.
  3. Final Answer:

    Missing curly braces around do block -> Option B
  4. Quick Check:

    Multiple statements need braces in do-while [OK]
Quick Trick: Use braces for multiple statements in loops [OK]
Common Mistakes:
  • Thinking increment operator ++ is invalid
  • Assuming condition syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes