While-4

 

Example of JavaScript while statement:

 
 
 
<!DOCTYPE html> <html> <head> </head> <body> <button onclick="myFunction()">Click it</button> <p id="sample"></p> <script> function myFunction() { var sum = 0; var number = 1; while (number <= 50) { sum += number; number++; } alert("Sum = " + sum); } document.getElementById("sample").innerHTML = i; </script> </body> </html>
Output