< Prev
Next >

C++ For Loop

C++ language provides us a powerful loop through which we could execute statements in a loop(again and again), until the point when the boolean condition of the loop returns true. This loop is known as for loop and it has three segments -

The third segment of the for loop declaration i.e. iteration of counter can be intentionally left blank from its declaration and can be specified within the body of for loop. In other words, the counter of for loop can also be incremented in the body of for loop.

// C++ for loop example 


using namespace std;
int main() //main method starts

for(int counter = 0; counter<3; ) // counter iteration part is intentionally left 
	cout<<"counter = " <<counter <<"\n";
	counter++;		  // counter is incremented/iterated in the body of for-loop 

return 0;
}// main method ends and program ends too


counter = 0
counter = 1
counter = 2

Please share this article -

< Prev
Next >
< Nested If Else Statement
Do-While Loop>


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition