- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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.
- Related Articles
- How to use PowerShell Break statement with the While Loop?
- How to use PowerShell break statement with the For loop?
- How to use PowerShell Break statement with the Switch command?
- How can I use a label with break statement in JavaScript?
- How to use PowerShell break statement in foreach loop?
- What is the difference between break with a label and without a label in JavaScript?
- What is PowerShell Break statement?
- break, continue and label in Java loop
- Describe JavaScript Break, Continue and Label Statements
- How to use PowerShell as a Calculator? Or How to use PowerShell for arithmetic operations?
- How to use the ValidateLength attribute in PowerShell?
- How to use the Timeout command in PowerShell?
- How to use the tree command in PowerShell?
- How to use the ErrorActionPreference variable in PowerShell?
- How to use the ErrorAction parameter in PowerShell?

Advertisements