C++ for loop is similar to the while loop; It continues to execute a block of code until the predefined condition is met. This is an entry-controlled loop. This tutorial will teach you how to use the for loop in C++.

The basic format of the for loop statement is:


for ( init; condition; increment )

Figure - Flowchart of the for loop:


Example C++ program to demonstrate the 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:


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram