Break statement: The break statement is used to jump out of a loop. It can be used to “jump out” of a switch() statement. It breaks the loop and continues executing the code after the loop.
Example:
<!DOCTYPE html> <html> <head> <title> JavaScript Break statement </title> </head> <body style="text-align:center;"> <div> <h1>GeeksForGeeks</h1> <h2>JavaScript Break</h2> </div> <p id="GFG"></p> <script> var content = ""; var i; for (i = 1; i < 1000; i++) { if (i === 6) { break; } content += "Geeks" + i + "<br>"; } document.getElementById("GFG").innerHTML = content; </script> </body> </html> |
Output:

Continue statement: The continue statement “jumps over” one iteration in the loop. It breaks iteration in the loop and continues executing the next iteration in the loop.
Example:
<!DOCTYPE html> <html> <head> <title> JavaScript continue statement </title> </head> <body style="text-align:center;"> <div> <h1>GeeksForGeeks</h1> <h2>JavaScript continue</h2> </div> <p id="GFG"></p> <script> var content = ""; var i; for (i = 1; i < 7; i++) { if (i === 4) { continue; } content += "Geeks" + i + "<br>"; } document.getElementById("GFG").innerHTML = content; </script> </center> </body> </html> |
Output:

JavaScript labels: In JavaScript, the label statements are written as the statements with a label name and a colon.
Syntax:
- break statements: It is used to jump out of a loop or a switch without a label reference while with label reference, it used to jump out of any code block.
break labelname;
- continue statements: It used to skip one loop iteration with or without a label reference.
continue labelname;
Example: This example use break label statements.
<!DOCTYPE html> <html> <head> <title> JavaScript continue statement </title> </head> <body style="text-align:center;"> <div> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>JavaScript break</h2> </div> <p id="GFG"></p> <!-- Script to use break label --> <script> var val = ["Geeks1", "Geeks2", "Geeks3", "Geeks4", "Geeks5"]; var print = ""; breaklabel: { print += val[0] + "<br>" + val[1] + "<br>"; break breaklabel; print += val[2] + "<br>"+ val[3] + "<br>" + val[4]; } document.getElementById("GFG").innerHTML = print; </script> </body> </html> |
Output:

Example: This example uses continue label.
<!DOCTYPE html> <html> <head> <title> JavaScript continue label </title> </head> <body style="text-align:center"> <div> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>JavaScript continue</h2> </div> <p id="GFG"></p> <!-- Script to use continue label --> <script> var val = ["Geeks1", "Geeks2", "Geeks3", "Geeks4"]; var val1=["Geeks","For","Geeks"] var print = ""; print += val1[0] + "<br>"; print += val1[1] + "<br>"; print += val1[2] + "<br>"; continuelabel: { print += val[0] + "<br>"; print += val[1] + "<br>"; continue continuelabel; print += val[2] + "<br>"; print += val[3] + "<br>"; } document.getElementById("GFG").innerHTML = print; </script> </body> </html> |
Output:

Example: This example illustrates without using any label.
<!DOCTYPE html> <html> <head> <title> No label in JavaScript </title> </head> <body style="text-align:center;"> <div> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>JavaScript No label</h2> </div> <p id="GFG"></p> <script> var val = ["Geeks1", "Geeks2", "Geeks3", "Geeks4"]; var val1=["Geeks","For","Geeks"] var print = ""; labelloop:{ print += val1[0] + "<br>"; print += val1[1] + "<br>"; print += val1[2] + "<br>"; } print+="<br>"; labelloop1: { print += val[0] + "<br>"; print += val[1] + "<br>"; print += val[2] + "<br>"; print += val[3] + "<br>"; } document.getElementById("GFG").innerHTML = print; </script> </body> </html> |
Output:

Recommended Posts:
- What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
- Difference between break and continue in PHP
- What is the use of number after “break” or “continue” statements in PHP ?
- continue command in Linux with examples
- How to break nested for loop using JavaScript?
- PHP break (Single and Nested Loops)
- Break and Next statements in R
- CSS page-break-before Property
- CSS | box decoration break Property
- CSS | word-break Property
- How to break line without using <br> tag in HTML / CSS ?
- Tips for restarting career after a break
- break command in Linux with examples
- CSS | page-break-after Property
- CSS | page-break-inside Property
- How to insert line break before an element using CSS?
- How to prevent column break within an element?
- How to break an outer loop with PHP ?
- How to break _.each() function in Underscore.js ?
- How to define a possible line-break using HTML5 ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


