C++ for loop
for loop know as loop making statement because it's depend on given condition and increment value.
for loop declare initialization condition and increment in the same line in for parameter.
for loop execute loop statements multiple times depends on condition and increment.
for loop statement execute loop statements while condition is true.while condition becomes false it'll goes out of loop
Syntax of for loop is very simple
//variable initialization
for loop declare initialization condition and increment in the same line in for parameter.
for loop execute loop statements multiple times depends on condition and increment.
for loop statement execute loop statements while condition is true.while condition becomes false it'll goes out of loop
Syntax of for loop is very simple
//variable initialization
for(initialization ; condition ; increment){
//loop statemets
}
}
Example
for
- #include <iostream>
- using namespace std;
- int main( ){
- //initialization , Condition , increment
- for(int x = 0 ; x < 4 ; x++){ // 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
Animated Gif of for loop statement
Watch Video
C++ for loop for Beginners Lecture in Urdu Hindi
Comments
Post a Comment