Skip to content

How does a while loop start in JavaScript | Code

  • by

JavaScript while loop starts by evaluating the condition. If the condition expression is true the statement is executed. If the condition is false, the statement(s) is not executed, and while loop ends.

while (condition)
{
  statement(s);
}

statement(s): A statement that is executed as long as the condition evaluates to true.

Example while loop start in JavaScript

Simple HTML example code.

<!DOCTYPE html>
<html>
<head>

  <script>
    var i = 1;
    while (i < 5) 
    {
      console.log(i);
       i++; // i=i+1 same thing
     }
   </script>

 </head>

</html>

Output:

How does a while loop start in JavaScript

Do comment if you have any doubts or suggestions on this JS loop topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading