break-2

 

Example of JavaScript break statement:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p id="sample"></p> <script> var x = 1; document.write("Entering the loop<br /> "); while (x < 10) { if (x == 4){ break; } x = x + 1; document.write( x + "<br />"); } document.write("Exiting the loop!<br /> "); </script> </body> </html>
Output