title: Java For Loop - What is i++ doing in For Loop?
body: <p>So program problem, the program will print 4. My question is what does i++ do in the for loop? The i++ is throwing me off a bit because I'm thinking when the for loop runs, i=1 intially, the for loop runs, now i = 2, but because there is an i++ inside the for loop after total+= i, my thinking is that it goes from i = 1 to i = 3. </p>
  
  <pre><code>public class LoopExample {
  
      public static void main(String[] args) {
          int total = 0;
  
          for (int i = 1; i &lt; 5; i++)
  
          {
  
          total += i;
  
          i++;
  
          }
  
          System.out.println(total);
  
       }
  
  }
  </code></pre>