home > resources > c++ coding standard > online version

Braces Usage

All if, while and do statements must either have braces or be on a single line.

Always Uses Braces Form, even if there is only a single statement within the braces.

Justification

  • Easier to read, you just have to scan for one form.
  • Uniform idiom for scop blocks since they are all encolsed in braces.
  • It provides a more consistent look.
  • This doesn't affect execution speed and it's easy to apply.
  • It ensures that when someone adds a line of code later there are already braces and they don't forget.

Example 3-3. Brace Usage Example

if (1 == somevalue)
{
   somevalue = 2;
}