

- 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 to label a block in JavaScript?
A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement.
Syntax
Here’s the syntax −
{ //List of statements }
To add a label to a block, use the following −
Identifier_for_label: { StatementList }
Let’s use it for break statement. You can try to run the following code to use labels to control the flow, with break statement
Example
<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 to declare Block-Scoped Variables in JavaScript?
- Block Scoping in JavaScript.
- What is a block statement in JavaScript?
- How to label a patch in matplotlib?
- Implementing block search in JavaScript
- What is the difference between break with a label and without a label in JavaScript?
- How to change button label in confirm box using JavaScript?
- How to change button label in alert box using JavaScript?
- How can I use a label with break statement in JavaScript?
- How can I use a label with continue statement in JavaScript?
- How to label a line in Matplotlib (Python)?
- How to create a label using JavaFX?
- Does JavaScript support block scope?
- What are label statements in JavaScript?
- How to create a hyperlink with a Label in Tkinter?
Advertisements