Do-while loop code
Difference between while and do-while?
'do-while' loop is similar to while loop and the only difference here is that the set of statements are executed first and the condition is checked next.Syntax:do
// set of statements that will be executed
Here the statements are added under do loop and while condition is checked at the end of loop. In 'Do While' the statements are executed once even if the condition will fail.
document.write("Testing DO-While loop");
In the example the condition is 'i' should not be equal to zero. The statements are executed and the condition is checked. The condition failed. The pointer comes out of the loop. So the statements are executed once even when the condition fails.