title: Nested Loop Recursion
body: <p>I am learning recursions and I wanna to rewrite the following code with some "n" number of nested loops in terms of recursion</p>
  
  <pre><code>for (int a = 0; a &lt; N; a++) {      //first loop
          for (int b = a + 1; b &lt; N; b++) {       //second loop
              for (int c = b + 1; c &lt; N; c++) {       // and for example n-th loop
                  str = " ( " + Integer.toString(a)
                          + " , " + Integer.toString(b)
                          + " , " + Integer.toString(c) +" ) ";
                  stringList.add(str);
              }
          }
      }
  </code></pre>
  
  <p>And when I call the </p>
  
  <pre><code>System.out.println(stringList);
  </code></pre>
  
  <p>The output should be as following</p>
  
  <pre><code>[ ( 0 , 1 , 2 ) ,  ( 0 , 1 , 3 ) ,  ( 0 , 2 , 3 ) ,  ( 1 , 2 , 3 ) ]
  </code></pre>
  
  <p>for N = 4 and 3 nested loops or</p>
  
  <pre><code>[ ( 0 , 1 , 2 ) ,  ( 0 , 1 , 3 ) ,  ( 0 , 1 , 4 ) ,  ( 0 , 2 , 3 ) ,  ( 0 , 2 , 4 ) ,  ( 0 , 3 , 4 ) ,  ( 1 , 2 , 3 ) ,  ( 1 , 2 , 4 ) ,  ( 1 , 3 , 4 ) ,  ( 2 , 3 , 4 ) ]
  </code></pre>
  
  <p>for N = 5 and 3 nested loops</p>
  
  <p>I have tried to write whis code</p>
  
  <pre><code> public static void recursionLoop(int i, int N, int M){  //M is the number of loops 
                                  //N is the highest number the programm should reach
            List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
              for (int a = i; a &lt; N - 1; a++) {
                  if (M &gt; 0) {
                      smartIter(i + 1, N, M - 1);
                      list.add(a);
  
                  }
              }
  </code></pre>
  
  <p>I cannot figure out how to reproduce my code to control the number of loops and the "N" number using recursion</p>
  
  <p>Can you help me please, I am really want to undestand the way it should be written and logics of recursion</p>