What is JavaScript do-while Loop and How to use it

What is Javascript do while loop

In this article, we will see what is a javascript do-while loop with examples. Do-while is similar while loop, the difference between the while and do-while loop is, the while loop is the entry control loop whereas the do-while loop is the exit control loop. In the Entry control loop means the condition is checked at the beginning of the loop whereas in the exit control loop condition is checked at the end of the loop.

Do while loop

It is also called an Exit control loop. The browser executes the statements in a do-while loop at least once. And then repeatedly executes the statements in a do-while loop as long as the given condition expression is true.


}while(conditional expression); //condition is checked at the end of the loop


var i =1; //Initialization
do {
document.write("Hello World <br/>");

what is javascript do while loop

Note: When you want to execute some set of statements at least once, whether the given conditional expression evaluates to true or false not matters, then use do-while loop.

READ ALSO  Why I Strongly Recommend using Triple Equals in JavaScript

Leave a Reply