Do While Statement
You will use do...while Loop, when you want to first perform a statement and then check the condition whether to perform statement again or not.
- The statements gets executed first. Then the condition is evaluated.
- If the condition evaluates to true, the statements inside the do statement are executed again.
- if the condition evaluates to false, the statements didn't get executed.
- This process continues until the condition evaluates to false. Then the do..while loop stops.
Flow Chart :
Difference Between do...while and while loop.
The Key Difference between them is :
First Program is to Print Hello World 10 Times.
You must be confused, why the Hello World is printed, without matching the condition.
This is the game of do...while , here statements gets executed first then it check for the conditions.
After Printing Hello World first time, its checks for the conditions and results false. So, Loop gets terminated.