title: How the counter works? / Very basic Java
body: <p>I have a code from a book with a counter in it. I don't understand why it works the way it does. To be specific, how does it happen that counter counts the lines generated by "for" loop? I see that there is an "if" loop with relational operator and conditional expression but it's still isn't clear to me how the code "knows" to count the lines.  Here is a code :</p>
  
  <pre><code>*/  
  class GalToLitTable {  
  public static void main(String args[]) {  
  double gallons, liters; 
  int counter; 
  
  counter = 0; 
  for(gallons = 1; gallons &lt;= 100; gallons++) { 
    liters = gallons * 3.7854; // convert to liters 
    System.out.println(gallons + " gallons is " + 
                       liters + " liters."); 
  
    counter++; 
    // every 10th line, print a blank line        
    if(counter == 10) { 
      System.out.println(); 
      counter = 0; // reset the line counter 
     } 
    } 
   }   
  </code></pre>
  
  <p>Any help would be much appreciated </p>