Javascript examples for Statement:while
while Loop through a block of code as long as a variable (i) is less than 5:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w ww .j av a 2 s . c om var text = ""; var i = 0; while (i < 5) { text += "<br>The number is " + i; i++; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>