Search code examples
javac++syntaxlanguage-theory

Why semicolon is not required after a curled bracket?


I know that a semicolon is required after a statement (I'm talking about Java, C++, and similar languages), but is not required after a curled bracket. Why so?

if (a > b) 
  printf("hello!"); // semicolon is mandatory

if (a > b) {
  printf("hello!");
} // semicolon is not required

What is the reason? I mean, what is the theory behind this?


Solution

  • Because curly brackets are used for grouping statements, but they are not statements themselves.