Using break, continue, and return

by Jun 26, 2014

There are two special keywords in PowerShell that you can use in loops: break and continue.

With continue, the loop continues but skips the remaining code. When you issue a break, the loop ends prematurely but returns all results.

In addition, there is the keyword return. It will always immediately exit the current scope. So when you issue "return" in a function, then the function will exit, and when you issue "return" in a script, then the script will exit.

Twitter This Tip! ReTweet this Tip!