Development guide

Flow Control

The code following a case label must always be terminated by either a break statement, a return statement or a throw statement.

If the code following a case label is not terminated by break, the execution continues after the next case label. This means that poorly tested code can be erroneous yet still seem to work.

A switch statement must always contain a default branch that handles unexpected cases. The default label is always the last label in a switch statement.
Case labels (and the default label) in a switch statement are always placed one indentation level higher as the switch statement.
Never use goto.

goto breaks the control flow and can lead to code that is difficult to comprehend. In addition, there are limitations for when goto can be used. For example, it is not permitted to jump past a statement that initializes a local object having a destructor.

The choice of loop construct (for, while or do while) should depend on the specific use of the loop.

Each loop construct has a specific usage. A for loop is used only when the loop variable is increased by a constant amount for each iteration and when the termination of the loop is determined by a constant expression. In other cases, while or do while should be used. When the terminating condition can be evaluated at the beginning of the loop, while should be used; do while is used when the terminating condition is best evaluated at the end of the loop.

Use break to exit a loop if this avoids the use of flags.
Use inclusive lower and exclusive upper limits.

Instead of saying that x is in the interval x >= 23 and x <= 42, use the limits x >= 23 and x < 43. The following important claims then apply: the size of the interval between the limits is the difference between the limits; the limits are equal if the interval is empty. the upper limit is never less than the lower limit. Being consistent in this regard helps to avoid many difficult bugs.