

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How can I use a label with break statement in JavaScript?
Starting from JavaScript 1.2, a label can be used with break statement to control the flow more precisely. A label is simply an identifier followed by a colon (:) that is applied to a statement or a block of code.
Example
You can try to run the following code to learn how to work with labels with break statement
<html> <body> <script> document.write("Entering the loop!<br /> "); outerloop: // This is the label name for (var i = 0; i < 5; i++) { document.write("Outerloop: " + i + "<br />"); innerloop: for (var j = 0; j < 5; j++) { if (j > 3 ) break ; // Quit the innermost loop if (i == 2) break innerloop; // Do the same thing if (i == 4) break outerloop; // Quit the outer loop document.write("Innerloop: " + j + " <br />"); } } document.write("Exiting the loop!<br /> "); </script> </body> </html>
- Related Questions & Answers
- How can I use a label with continue statement in JavaScript?
- How to use PowerShell Break with the Label.
- How can I use goto statement in JavaScript?
- Can we use break statement in a Python if clause?
- What is the difference between break with a label and without a label in JavaScript?
- 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 to use the break statement to come out of a loop in JavaScript?
- How can I break an outer loop with PHP?
- How to use PowerShell break statement in foreach loop?
- What is break statement in JavaScript?
- Java break statement with switch
- Describe JavaScript Break, Continue and Label Statements
- How do we use a break statement in while loop in C#?
Advertisements