Updated on Kisan Patel
The do-while loop is similar to the while loop, the only difference is that the do… while loop executes at least once and then repeat till the specified condition is true.
The syntax of do…while is
do { .... } while (condition)
The following JavaScript illustrates use of do…while
counter = 1; do { document.write("This statement number: " + counter); document.write("<br/>"); counter++; } while (counter <= 5);
See the Pen XbQebr by Kisan (@pka246) on CodePen.