Create nested for loop - C++ Statement

C++ examples for Statement:for

Description

Create nested for loop

Demo Code

#include <iostream>
using namespace std;
int main()//from   www.jav  a  2  s .c  om
{
   const int MAXI = 5;
   const int MAXJ = 4;
   int i, j;
   for (i = 1; i <= MAXI; i++)    // start of outer loop
   {
      cout << "\ni is now " << i << endl;
      for (j = 1; j <= MAXJ; j++)  // start of inner loop
         cout << "  j = " << j;      // end of inner loop
   }                             // end of outer loop
   cout << endl;
   return 0;
}

Result


Related Tutorials