# How to use PowerShell Break statement with the Switch command?

PowerShellMicrosoft TechnologiesSoftware & Coding

#### Powershell for beginners

15 Lectures 3.5 hours

#### Learning Task Automation using Windows PowerShell

35 Lectures 2.5 hours

#### The Complete PowerShell 7 course: Beginner To Advanced

Most Popular

145 Lectures 12.5 hours

In Switch command, when the single value passed and if it matches the condition then the loop gets automatically exited but when there are multiple values passed and if the value matches the first condition and if you want to terminate the loop then you can use the Break statement. An example is given below.

## Example

Switch (3,5){
1 {"This is One"}
2 {"This is Two"}
3 {"This is Three"; Break}
4 {"This is Four"}
5 {"This is Five"; Break}
}

## Output

This is Three

You can notice in the above output that second parameter 5 won’t be executed because the 3 has already been executed with the break statement.

Updated on 12-Mar-2020 07:28:38