Control structures are code statements that impact the program’s control flow (e.g., if statements, for loops, etc.)

Why is this an issue?

While not technically incorrect, the omission of curly braces can be misleading and may lead to the introduction of errors during maintenance.

In the following example, the two calls seem to be attached to the if statement, but only the first one is, and checkSomething will always be executed:

if (condition)  // Noncompliant
  executeSomething();
  checkSomething();

Adding curly braces improves the code readability and its robustness:

if (condition) {
  executeSomething();
  checkSomething();
}

The rule raises an issue when a control structure has no curly braces.

Exceptions

The rule doesn’t raise an issue when the body of an if statement is a single return, break, or continue and is on the same line.

Resources