title: A single-line loop with a mandatory pair of braces in Java
body: <p>The code in the following snippet works just fine. It counts the number of objects created using a static field of type <code>int</code> which is <code>cnt</code>.</p>
  
  <pre><code>public class Main
  {
      private static int cnt;
  
      public Main()
      {
          ++cnt;
      }
  
      public static void main(String[] args)
      {
          for (int a=0;a&lt;10;a++)
          {
              Main main=new Main();
          }
  
          /*for (int a=0;a&lt;10;a++)
              Main main=new Main();*/
  
          System.out.println("Number of objects created : "+cnt+"\n\n");
      }
  }
  </code></pre>
  
  <p>It displays the following output.</p>
  
  <pre><code>Number of objects created : 10
  </code></pre>
  
  <p>The only question is that when I remove the pair of curly braces from the above <code>for</code> loop (see the commented <code>for</code> loop), a compile-time error is issued indicating </p>
  
  <blockquote>
    <p>not a statement.</p>
  </blockquote>
  
  <p>Why in this particular situation, a pair of braces is <strong>mandatory</strong> even though the loop contains only <strong>a single statement</strong>?</p>