Break out of for loop with if and break statement - C++ Statement

C++ examples for Statement:break

Description

Break out of for loop with if and break statement

Demo Code

#include <iostream>

using namespace std;

int main()/*  w  ww  .ja va 2s .  c om*/
{
    int i;

    for (i=0; i<10; i++)
    {
        cout << i << " ";
        if (i == 5)
        {
            break;
        }
        cout << i * 2 << endl;
    }

    cout << "All Finished!" << endl;

    return 0;
}

Result


Related Tutorials