First it will execute the statements inside the loop and then after reaching the end, it will check the condition inside the while. If the condition is True then it will repeat the process. If the condition fails then Do While Loop will be terminated.
Flow chart sequence is:
- First we initialize our variables, next it will enter into the Do While loop.
- It will execute the group of statements inside the loop.
- Now it will check for the condition. If the condition is True, then the statements inside the Do while loop will be executed again. It will continue the process as long as the condition is True.
- If the condition is False then it will exit from the loop
var number = 6, total=0;
total = total + number;
document.write("<br\>Number = " + number);
document.write("<br\>Total Value is = " + total);
}while (number <= 10);
document.write("<br\>Total Value from outside the Loop is = ", total);
- First we declared the variable number and initialized to 6 and total variable is initialized to 0.
- Next, number is added to the total.
- In the next line we used ++ operator to increment the number value.
- After this line, number is tested against the while condition.If the condition results true then it will repeat the process again otherwise, it will exit from the loop
- In the next line we used one more statement to show that it is coming from outside the do while loop.
Let us enter value greater than 10 to see, what will happen?
If you observe from the above screenshot, we entered value 11 and it still display the total as 11 because after executing that code it checked the while condition and it failed so it exit from the loop.
Thank You for Visiting Our Blog