The Continue
operator works in For
, ForEach
, While
and Do
loops. It skips the current iteration of the loop, jumping to the top of the innermost loop.
$i =0
while ($i -lt 20) {
$i++
if ($i -eq 7) { continue }
Write-Host $I
}
The above will output 1 to 20 to the console but miss out the number 7.
Note: When using a pipeline loop you should use return
instead of Continue
.