title: How does a for loop increment?
body: <p>The sum is -9 but i'm having trouble figuring out why. I don't understand how the j-- in the for loop will increment. It should be incremented after the body is executed, right? But doesn't the initialization of the for loop make j-- pointless? So I assume that on the 2nd iteration j becomes 2 because of i++. Could someone help look at this the right way?</p>
  
  <pre><code>public static void whatsTheSum(){
      int sum = 1;
      int i = 1;
  
      while(i &lt; 5){
          for(int j = i; j &gt; 0; j--)
              sum += (j - i);
          i++;
      }
      System.out.println(sum);
  }
  </code></pre>