Synopsis: | The break statement shall not be used to exit from an iteration statement ("for" or "while"). |
Language: | C |
Severity Level: | 6 |
Category: | Statement and Blocks |
Description: |
Justification "break" statements cause breaks in the normal structured control flow of a program. For this reason they shall be avoided (apart from use in switch statements) as they affect the readability and maintainability of the code. Example 1 for (i = 0; i < n; i++) { if (c[i] == ' ') { break; /* WRONG */ } } Example 2 while (c[0] == ' ') { ...c... break; /* WRONG */ } Example 3 i = 0; while ((i < n) && (c[i] != ' ')) /* RIGHT */ { i++; } /* status: i == n || ((0 <= i < n) && (c[i] == ' ')) */ |