Next: 6 Constants  Up: index  Previous: 4 Complexity  Contents

5 Control Flow

5.1

High Integrity CPP Rule

Follow each flow control primitive ('if', 'else', 'while', 'for', 'do' and 'switch') by a block enclosed by braces, even if the block is empty or contains only one line.

5.2

High Integrity CPP Rule

For boolean expressions ('if', 'for', 'while', 'do' and the first operand of the ternary operator '?:') involving non-boolean values, always use an explicit test of equality or non-equality.

5.3

High Integrity CPP Rule

Avoid conditional expressions that always have the same result.

5.4

High Integrity CPP Rule

Follow each non-empty case statement block in a switch statement with a break statement.

5.5

High Integrity CPP Rule

Do not alter a control variable in the body of a for statement.

5.6

High Integrity CPP Rule

Do not alter a control variable more than once in a for, do or while statement.

5.7

High Integrity CPP Guideline

The control variable in a for loop should be tested against a constant value, not a function or expression.

5.8

High Integrity CPP Rule

Do not use 'goto'.

5.9

High Integrity CPP Rule

Ensure that every compound statement except the body of a switch statement has a single entry point and (barring the propagation of C++ exceptions) a single exit point.

5.10

High Integrity CPP Rule

For functions with non-void return type, ensure all paths have a return statement that contains an expression of the return type.

5.11

High Integrity CPP Rule

Include explicit cases for all alternatives in multi-way conditional structures.

5.12

High Integrity CPP Rule

Declare for loop control variables within the for statement instead of using an existing variable.


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP