C++ break statement Put a break statement inside a nested loop

Introduction

The break statement applies to the middle loop as shown here:


#include <iostream>

using namespace std;

int main()//  w w w .j  a va2s  . c om
{
    int x,y,z;

    for (x = 1; x <= 3; x++)
    {
        for (y = 1; y < 3; y++)
        {
            if (y == 2)
               break;
            for (z = 1; z < 3; z++)
            {
                cout << x << " " << y;
                cout << " " << z << endl;
            }
        }
    }

    return 0;
}



PreviousNext

Related