Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Javascript do while loop

Notes:

Javascript do while loop: Exit control loop

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 conditional expression is true.

Syntax:
initialization;
do
{
statement(s);
increment/decrement;
} while(conditional expression); // Condition is checked at the end of the loop

Ex:
var i=1;
do{
document.write(“Hello World <br/>”);
i++;
}while(i<=5);

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.

Interview Questions: