Put a break statement or a continue statement inside a nested loop. - C++ Statement

C++ examples for Statement:break

Introduction

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

Demo Code

#include <iostream>

using namespace std;

int main()//from   w ww .j a v  a 2  s . c o m
{
    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;
}

Result


Related Tutorials