title: triple nested for loop in java logic
body: <p>I'm running this code from a textbook called java just in time, and I can see the output but I don't full understand the process of this nested for loop.</p>
  
  <pre><code>for (int die1 = 1; die1 &lt;= 6; die1++)
      for (int die2 = 1; die2 &lt;= 6; die2++)
          for (int die3 = 1; die3 &lt;= 6; die3++)
              System.out.println(die1 + die2 + die3 + " From " + die1 + "+" + die2 + "+" + die3);
  </code></pre>
  
  <p>The output results of the die numbers goes like this,
  111
  112
  113
  114
  115
  116</p>
  
  <p>Which I can make sense of. The third for loop is cycled 6 times where die3 is incremented each time and the output is displayed.</p>
  
  <p>The next lines of output give</p>
  
  <p>121
  122
  123
  124
  125
  126</p>
  
  <p>which is where I become a little confused. I can see that die2 has now been incremented by 1 and increases to two, but I am confused as to how the value of die3 has now gone back to 1 and is incrementing through again. Can someone explain to me the process of what is going on in this nested for loop ? Thanks</p>
  
  <p>In addition is the logic changed by applying "{}" brackets to each loop ?</p>