Difference Between While and Do-While in Tabular Form.

Basis TermsWhileDo-While
DefinitionA while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block.
WorkingWhile loop is executed only when given condition is true.do-while loop is executed for first time irrespective of the condition. After executing while loop for first time, then condition is checked.
Condition CheckingChecking the condition before executing statements.Checking the condition after having executed statement.
FlowChart Diagram
IterationsThe iterations do not occur if, the condition at the first iteration, appears false.The iteration occurs at least once even if the condition is false at the first iteration.
Semi-colon UseNot usedUsed at the end of the loop
Syntax Examplewhile ( condition) {
statements; //body of loop
}
do{
statements; // body of loop.
} while( Condition );
(Visited 133 times, 3 visits today)
Share with Friends :