Bird
0
0

Which of the following is the correct syntax to use break inside a PowerShell for loop?

easy📝 Syntax Q3 of 15
PowerShell - Control Flow
Which of the following is the correct syntax to use break inside a PowerShell for loop?
Afor ($i=0; $i -lt 5; $i++) { if ($i -eq 3) break; continue }
Bfor ($i=0; $i -lt 5; $i++) { if ($i -eq 3) { break } }
Cfor ($i=0; $i -lt 5; $i++) { break if ($i -eq 3) }
Dfor ($i=0; $i -lt 5; $i++) { if ($i -eq 3) { continue } break }
Step-by-Step Solution
Solution:
  1. Step 1: Review correct break syntax in PowerShell loops

    The break statement is used inside an if block with curly braces or as a single statement.
  2. Step 2: Analyze each option for syntax correctness

    for ($i=0; $i -lt 5; $i++) { if ($i -eq 3) { break } } uses correct syntax: if ($i -eq 3) { break }. Options A and B misuse continue or have misplaced statements. for ($i=0; $i -lt 5; $i++) { break if ($i -eq 3) } has incorrect placement of break.
  3. Final Answer:

    for ($i=0; $i -lt 5; $i++) { if ($i -eq 3) { break } } -> Option B
  4. Quick Check:

    Correct break syntax = D [OK]
Quick Trick: Use break inside if with braces for clarity [OK]
Common Mistakes:
  • Placing break outside if incorrectly
  • Mixing break and continue in wrong order
  • Missing braces around break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes