Recall & Review
beginner
What does the
break statement do in a PowerShell loop?The
break statement immediately stops the entire loop and exits it, continuing with the code after the loop.Click to reveal answer
beginner
What is the purpose of the
continue statement in PowerShell loops?The
continue statement skips the rest of the current loop iteration and moves to the next iteration of the loop.Click to reveal answer
beginner
How does
break differ from continue in PowerShell loops?break stops the whole loop immediately, while continue skips only the current iteration and continues looping.Click to reveal answer
beginner
Example: What will this PowerShell code output?<br>
for ($i=1; $i -le 5; $i++) { if ($i -eq 3) { break } Write-Output $i }It will output:<br>1<br>2<br>Because when $i equals 3,
break stops the loop immediately.Click to reveal answer
beginner
Example: What will this PowerShell code output?<br>
for ($i=1; $i -le 5; $i++) { if ($i -eq 3) { continue } Write-Output $i }It will output:<br>1<br>2<br>4<br>5<br>Because when $i equals 3,
continue skips that iteration and moves to the next one.Click to reveal answer
What happens when
break is used inside a PowerShell loop?✗ Incorrect
break stops the entire loop immediately and exits it.What does
continue do in a PowerShell loop?✗ Incorrect
continue skips the rest of the current loop iteration and moves to the next one.Which statement would you use to skip printing number 3 but continue the loop in PowerShell?
✗ Incorrect
continue skips the current iteration but keeps the loop running.If you want to stop a loop as soon as a condition is met, which statement is best?
✗ Incorrect
break immediately stops the loop when the condition is met.What will this code output?<br>
for ($i=1; $i -le 4; $i++) { if ($i -eq 2) { continue } Write-Output $i }✗ Incorrect
When $i equals 2,
continue skips printing 2, so output is 1 3 4.Explain in your own words how
break and continue control the flow inside PowerShell loops.Think about what happens when you want to stop everything vs just skip one step.
You got /3 concepts.
Write a simple PowerShell loop that prints numbers 1 to 5 but skips number 3 using
continue.Use an if statement inside the loop to check for 3 and skip it.
You got /4 concepts.