Home Segments Index Top Previous Next

418: Mainline

The following switch statement pattern contains no break statements. Thus, once execution begins, all subsequent statements up to the end of the switch statement are executed.

switch (integer-producing expression) { 
  case integer constant 1: statements for integer 1 
  case integer constant 2: statements for integer 2 
  ... 
  default: default statements 
} 

In general, when there is no break statement to terminate the execution of a sequence of statements, execution is said to fall through to the next sequence of statements, where execution continues, once again, in search of a break statement.

The reason for the fall-through feature is that you occasionally want to perform the same action in response to any of several conditions. Note carefully, however, that an inadvertently forgotten break is a common error.