While Loop In C++


while loop may be used where we don’t know how many times loop must be run.


Syntax of while loop in c++


initilization;

while(condition)

{

Statement;

incr/decr;

}


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


#include<iostream>

using namespace std;

int main(){

int i;

i=1;

clrscr();

while(i<=5)

{

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

i++;

}

return 0;

}



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