title: Recursion for cycle not increasing it's value before return statement
body: <pre><code>public class Main2 {
      private static int[] arr = new int[3];
      private static int[] values = new int[]{1, 2, 3, 4};
  
      public static void main(String[] args) {
          generateVariations(0);
      }
  
      private static void generateVariations(int index) {
          if (index == arr.length) {
              System.out.println(Arrays.toString(arr));
              return;
          }
          for (int i = index; i &lt; values.length; i++) {
              arr[index] = values[i];
              swap(i, index);
              generateVariations(index + 1);
              swap(i, index);
          }
  
      }
  
      private static void swap(int i, int index) {
          int temp = values[i];
          values[i] = values[index];
          values[index] = temp;
      }
  }
  </code></pre>
  
  <p>So in this code, the for loop in the <code>generateVariations</code> method doesn't increase the value of <code>i</code> until my code execution hits the <code>return</code> statement.  Why is this happening? I mean that <code>i</code> has the value of <code>index</code> as if the <code>i++</code> is absent, it only increases it self once a <code>return</code> statement is hit.</p>