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