C++ for loops

C++ for loops is very similar to a while loops in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line. for loop is an entry-controlled loop.

The basic format of for loop statement is:

for ( init; condition; increment )

Figure - Flowchart of for loop:


Example of a C++ Program to Demonstrate for loop

#include <iostream>
using namespace std;

int main ()
   /* local variable Initialization */   int n = 1,times=5;

   /* for loops execution */   for( n = 1; n <= times; n = n + 1 )
      cout << "C++ for loops: " << n <<endl;
   return 0;
Program Output: