C33. C Role of the break Statement


The Role of the break Statement
Now, let's take a closer look at the mysterious break statement. As we've seen, executing a break statement causes the program to "break" out of the switch statement; execution continues at the next statement after the switch.
The reason that we need break has to do with the fact that the switch state­ment is really a form of "computed jump." When the controlling expression is evaluated, control jumps to the case label matching the value of the switch expression. A case label is nothing more than a marker indicating a position within the switch. When the last statement in the case has been executed, control "falls through" to the first statement in the following case; the case label for the next case is ignored. Without break (or some other jump statement), control will flow from one case into the next.

No comments: