title: How to dynamically control the for-loop nested level?
body: <p>I am implementing some algorithm, in which the number of loop nested levels is determined by the input. </p>
  
  <p>For example, if the input is 2-dimensional, then there two nested for-loops, as below:</p>
  
  <pre><code>for(int i=0; i&lt;N; i++) {
      for(int j=i+1; j&lt;N; j++) {
          if(table[i][j] == -1) {
              for(int c=0; c&lt;C; c++) {
                  int ii = table[i][c];
                  int jj = table[j][c];
                  sort(ii, jj);
                  if((T[ii][jj] != -1 &amp;&amp; T[ii][jj] &lt; l)) {
                      T[i][j] = l;
                      break;
                  }
               }
           }
       }
  }
  </code></pre>
  
  <p>If the input is 3-dimensional, then it would be something like below:</p>
  
  <pre><code>for(int i=0; i&lt;N; i++) {
      for(int j=i+1; j&lt;N; j++) {
          for(int k=j+1; k&lt;N; k++) {
              if(table[i][j][k] == -1) {
                  for(int c=0; c&lt;C; c++) {
                      int ii = table[i][c];
                      int jj = table[j][c];
                      int kk = table[k][c];
                      sort(ii, jj, kk);
                      if((T[ii][jj][kk] != -1 &amp;&amp; T[ii][jj][kk] &lt; l)) {
                          T[i][j][k] = l;
                          break;
                      }
                  }
             }
        }
  }
  </code></pre>
  
  <p>If there are only these two case, then I can write two versions of nested for-loops. But the dimensions of input could be any value between <code>2</code> and <code>N</code>. In this case, how to control the nested loop level dynamically, or is there any alternative to go around of this?</p>