Javascript examples for Statement:break
Using the break statement with a label reference, to "jump out" of a nested for loop:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//www . j a va 2 s .c o m var text = ""; var i, j; Loop1: // The first for loop is labeled "Loop1" for (i = 0; i < 3; i++) { text += "<br>" + "i = " + i + ", j = "; Loop2: // The second for loop is labeled "Loop2" for (j = 10; j < 15; j++) { if (j === 12) { break Loop2; } document.getElementById("demo").innerHTML = text += j + " "; } } } </script> </body> </html>