Complete the code to stop the loop when the number is 5.
foreach ($i in 1..10) { if ($i -eq 5) { [1] } Write-Output $i }
The break statement stops the loop immediately when the condition is met.
Complete the code to skip printing the number 3 but continue the loop.
foreach ($i in 1..5) { if ($i -eq 3) { [1] } Write-Output $i }
The continue statement skips the current iteration and moves to the next one.
Fix the error in the loop to skip even numbers and print only odd numbers.
foreach ($num in 1..6) { if ($num % 2 -eq 0) { [1] } Write-Output $num }
Using continue skips even numbers and continues the loop to print only odd numbers.
Fill both blanks to stop the loop when number is 4 and skip printing number 2.
foreach ($i in 1..5) { if ($i -eq 2) { [1] } if ($i -eq 4) { [2] } Write-Output $i }
continue skips printing number 2, and break stops the loop at number 4.
Fill all three blanks to skip numbers less than 3, stop at 6, and print the rest.
foreach ($num in 1..7) { if ($num -lt [1]) { [2] } if ($num -eq [3]) { break } Write-Output $num }
Numbers less than 3 are skipped with continue. The loop stops at 6 using break. The blanks fill the values and commands accordingly.