Prev Demo
JavaScript
>
How To Break A Loop In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Break Loop</h1> <script> function TestFunction() { var i = 0; do { if (i == 2) { break; } alert(i); i++; } while (i < 5); } </script> <input type="button" id="btnTest" onclick="TestFunction()" value="Click me" /> </body> </html>
Note: We DO NOT save your trial code in our database.
Output