Difference Between While and Do-While in Tabular Form.
Basis Terms | While | Do-While |
---|
Definition | A 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. |
Working | While 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 Checking | Checking the condition before executing statements. | Checking the condition after having executed statement. |
FlowChart Diagram | | |
Iterations | The 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 Use | Not used | Used at the end of the loop |
Syntax Example | while ( condition) { statements; //body of loop } | do{ statements; // body of loop. } while( Condition ); |
(Visited 136 times, 1 visits today)