Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C++ for loops

    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:

    Syntax:

    for ( init; condition; increment )
    {
        statement(s);
    }

    Figure - Flowchart of the for loop:

    cplusplus-for

    Example C++ program to demonstrate the for loop:

    Example:

    #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:

    cplusplus-for-loops



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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.