How do...while loop works?

  • The codes inside the body of loop is executed at least once. Then, only the test expression is checked.
  • If the test expression is true, the body of loop is executed. This process continues until the test expression becomes false.
  • When the test expression is false, do...while loop is terminated.
  • Flowchart of do...while Loop

    Flowchart of do...while Loop

    Flowchart of do while loop in C++ programming
prog to print no from 1 to 10:-
#include<iostream.h>
void main()
{
int k;
k=1;
do
{
cout<<k<<endl;
k++;
}while(k<=10);
}
  • comparison Chart

    BASIS FOR COMPARISONWHILEDO-WHILE
    General Formwhile ( condition) {
    statements; //body of loop
    }
    do{
    .
    statements; // body of loop.
    .
    } while( Condition );
    Controlling ConditionIn 'while' loop the controlling condition appears at the start of the loop.In 'do-while' loop the controlling condition appears at the end of the loop.
    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.