Javascript examples for Statement:for
Omit the second parameter in for loop.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w ww.ja va2 s. c o m var cars = ["a","b","c","d","e"]; var text = ""; var i; for (i = 0;; i++) { if (i == 3) { break; } text += cars[i] + "<br>"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>