Site icon Dotnet Helpers

PowerShell : Continue Keyword

Continue Keyword in PowerShell

One of the things that is a bit confusing for powershell beginner is the Continue statement. This is partially because it does not act like it might in some other languages. Next question will arise, then what does the Continue statement do in Windows PowerShell? the answer is it returns flow to the top of the innermost loop that is controlled by a WhileFor, or Foreach statement. 

Example:

In the following example, program flow returns to the top of the While loop if value of $myValue variable is equal to 6. As a result, all the numbers between 1 and 10 are displayed except for 5:

Output:

The Continue keyword supports labels. A label is a name you assign to a statement in a script, so the continue will skip in the current loop and execute form the  assigned label location. Let we discuss more about the labels in upcoming articles.

Exit mobile version