The while loop repeatedly executes a block of statements until a particular condition is true. It first checks the condition and executes a block of statements if the condition is true.
Syntax:
while(condition){
//Block of statements
}
while(condition){
//Block of statements
}
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>
<html>
<head>
<script>
var num=1;
while (num<=10) {
document.write(num + "<br/>");
num++;
}
</script>
</head>
<body>
</body>
</html>
<html> <head> <script> var num=1; while (num<=10) { document.write(num + "<br/>"); num++; } </script> </head> <body> </body> </html>