
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use PowerShell Break with the Label
When the break statement is mentioned with the Label, PowerShell exits to the label instead of exiting the current loop.
Example
$i = 1 while ($i -lt 10) { Write-Output "i = $i" if($i -eq 5){ Write-Output "Break statement executed" Break :mylable } $i++ } Write-Output "Entering to another loop" $j = 1 :mylable while($j -lt 3){ Write-Output "j = $j" $j++ }
Output
i = 1 i = 2 i = 3 i = 4 i = 5 Break statement executed Entering to another loop j = 1 j = 2
As you can see in the above example when the value of 5 executed, the block containing label (mylable) is also executed and execution moves to another loop.
Advertisements