C++ For Loop

for loop statement is good alternative of while statement. This is most frequently used iterative structure. It is also a pre test loop structure.

Syntax

for ( Initialization  ; condition  ; increament / decrement )  {

      statements ;

}

To understand  Initialization, increament / decrement, condition and statements read while statement.

Example

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	// initialization.
	int a;
	
	// for loop statement.
	/* initialization, condition and increment
	   is going inside for loop statement.
	*/
	for ( a=1; a<=5; a++ ) {
		
		// output statement.
		cout<<"IMS\n";
		
	}
	return 0;
}

Output

output of for loop in C++

Comments
Login to TRACK of Comments.