

- 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
What are label statements in JavaScript?
JavaScript label statements are used to prefix a label to an identifier. A label can be used with break and continue 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. We will see two different examples to understand how to use labels with break and continue.
Example
You can try to run the following code to use labels to control the flow, 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>
Example
You can try to run the following code to use labels to control the flow, with continue statement
<html> <body> <script> document.write("Entering the loop!<br /> "); outerloop: // This is the label name for (var i = 0; i < 3; i++) { document.write("Outerloop: " + i + "<br />"); for (var j = 0; j < 5; j++) { if (j == 3) { continue outerloop; } document.write("Innerloop: " + j + "<br />"); } } document.write("Exiting the loop!<br /> "); </script> </body> </html>
- Related Questions & Answers
- Describe JavaScript Break, Continue and Label Statements
- What are control statements in C#?
- What are provision in financial statements?
- What are reserves in financial statements?
- What are decision making statements in C#?
- What are executable statements in C language?
- What are the types of statements in JDBC?
- Why are "continue" statements bad in JavaScript?
- Conditional statements in JavaScript
- What are the synonym statements of MySQL DESCRIBE?
- Why are Prepared Statements in JDBC faster than Statements? Explain?
- What are the Sources and Uses of Funds Statements?
- What is the difference between break with a label and without a label in JavaScript?
- What is Control Statements?
- What are the best practices for using if statements in Python?
Advertisements