Synopsis: | All control statements shall be fully brace enclosed. |
Language: | C |
Severity Level: | 3 |
Category: | NON-LANGUAGE ISSUES |
Description: |
All if, while, for, do and switch statements should be followed by a brace-enclosed compound statement. If only indentation is used to indicate that a single statement belongs to an "if", "while" or "for", it is a frequently occurring mistake to enhance this construct by adding another statement without supplying the now necessary {..} to indicate that both statements belong to the while. The practice of using {..} also aids readability. Example: while( ... ) i++; /* WRONG */ while( ... ) { i++; /* RIGHT */ } Example: for(...) i++; /* WRONG */ for(...) { i++; /* RIGHT */ } Example: if ( ... ); /* WRONG, no {} */ if ( ... ) { /* EMPTY*/ /* RIGHT */ } |