C++ do while loop
do While loop know as loop making statement because it's also depend on given condition and increment value.
do while loop execute loop statements multiple times depends on condition and increment.
while loop statement execute loop statements at least one time without processing condition. while condition is true it'll execute it again and again until condition become false. while condition becomes false it'll goes out of loop
Syntax of do while loop is very simple
//variable initialization
do while loop execute loop statements multiple times depends on condition and increment.
while loop statement execute loop statements at least one time without processing condition. while condition is true it'll execute it again and again until condition become false. while condition becomes false it'll goes out of loop
Syntax of do while loop is very simple
//variable initialization
do{
//loop statemets
//increment
}while( condition );
//loop statemets
//increment
}while( condition );
Example
do While
- #include <iostream>
- using namespace std;
- int main( ){
- int x = 10; //initialization
- do{
- cout << " Value of x = "<< x << endl ;
- x++; //increment
- }while( x < 4 ); // condition
- cout<<"Out of Loop \n"<<endl;
- return 0;
- }
Console :
Value of x = 10
Out of Loop
Animated Gif of do while loop statement
Watch Video
C++ do while loop for Beginners Lecture in Urdu Hindi
Comments
Post a Comment