What is while loop statement in JavaScript?

The most basic loop in JavaScript is the while loop. The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.


The syntax of while loop in JavaScript is as follows −

while (expression){
   Statement(s) to be executed if expression is true


You can try to run the following example to implement while loop

Live Demo

         var count = 0;
         document.write("Starting Loop ");
         while(count < 10){
            document.write("Current Count : " + count + "<br/>");
         document.write("Loop stopped!");