Return to top of a program loop, skip just this iteration of the loop.

In a For, ForEach or While loop you can add a continue statement to jump to the top of the innermost loop.

Choose the conditions under which you call the continue statement carefully, as it is easy to create an infinite loop.


Count to 10 but miss out the number 5:

PS> $i =0
    while ($i -lt 10)
          $i +=1 
          if ($i -eq 5) {continue}
          Write-Host $i

“Just don’t give up trying to do what you really want to do.
Where there is love and inspiration, I don’t think you can go wrong” ~ Ella Fitzgerald

Related PowerShell Cmdlets

Break - Exit a program loop.
Exit-PSSession - Exit PowerShell (or exit a script).
Return - Exit the current scope, (function, script, or script block).
Trap - Handle a terminating error.
While - Loop while a condition is True.

Copyright © 1999-2024
Some rights reserved