Do while loop in cpp

Do while loop in cpp is looping statement in c++.

Looping statement is used to iterate the statement (executed statement multiple times) with some condition.

Do while loop :- while loop executes the statement in block before evaluating expression.

This is equivalent to while loop, but it have to test the condition at the end of the loop.

It always executes at least once.(i .e either condition true or false block executed at least one time)

We write any number of statement in while loop enclosed in curly braces { }.

Do while loop syntax 

do {

//Statement 1

. .

Statement n;

}while(expression);

In above syntax we can see first we write do keyword and statement first statement are executed and at the end while having condition if condition is true then statement in while loop are executed.

do while example

do{

cout<<“technical seek”

}while(1)

In above Example ,do first executes the block after that while checked while(1) ,1 indicates condition true so the statement in do while executed.

Do while execution  : It always executes at least once

do while loop program in cpp

123456789101112131415161718192021222324252627#include <iostream>using namespace std;int main(){int i;i=1;cout<<“do while loop execution”;do //if condition is true{cout<<” i = “<<i<<endl;i ++; // Decrement value of i}while(i < 6);cout<<“do while completed “;    return 0;}

Output :

do while loop
do while loop

Program description

1. In above program we written do while loop to print value of i.

2. First we take initial value of i = 1

3. next we write do keyword and block of statement .

4. First the statement get executed i.e i=1.

5. Now while checks the condition i=2 >0 .Condition is true so statement in block executed and prints i = 2.

6. Similarly statement are executed with value of i till value of i =6.

7. In case i = 6 , condition gets false and execution comes out of the loop and rest of the code executed.