javascript while loop tutorial

The while loop repeatedly executes a block of statements until a particular condition is true. It first check the condition and executes a block of statements if condition is true.

Syntax:

while(condition){
 //Block of statements 
}

JavaScript while loop example:

<html>
<head>
<script>  
var num=1;  
while (num<=10)  {  
document.write(num + "<br/>");
num++;
}  
</script> 
</head>
<body> 
</body>
</html>

Try it:

JS Bin on jsbin.com