Do while loop in JavaScript works similar to while loop in javascript the only difference is that Do block executes at least once before while loop’s test condition. That’s why do block executes whether is satisfies the while condition or not.
Syntax of JavaScript do while loop
do
{
Code block to be executed;
}
while(var<=value);
Example of JavaScript do while loop
var i=1;
do
{
document.write('<font size=\"' + i + '\">Hello World</font><br />');
i++;
}
while(i<0);
Above example will display the “Hello World” string once before the while condition i<0 is being tested.
Continue to next tutorial: Javascript Array to learn how to store list of items into a single Javascript Array object.