Do While Loop In C++


The do while loop is exactly same as while loop the difference is that statement execute first before check condition always at least one condition will execute if the condition is false.


Syntax Of Do While In C++


Initilization;

Do

{

Statement;

incr/decr;

}while(condition);


Note: Semicolon must be included after while in do while loop.


Print Codeverb.com message for 5 times by using do while loop.

#include<iostream>

using namespace std;

int main(){

int i=1;

clrscr();

do

{

cout<<“Codeverb.com %d\n”,i;

i++;

}while(i<=5);

return0

}


Output:
Codeverb.com 1
Codeverb.com 2
Codeverb.com 3
Codeverb.com 4
Codeverb.com 5