Switch Statement

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Syntax: switch ( Expression ) Statement
 
*Semantics: The expression is computed and must of integer type (byte, int, or long) or of type char. If a matching case label is found within Statement, the execution jumps to that point. If not, the execution continues at the default label, if provided. Otherwise, Statement is skipped.
 
*Syntax of case labels: case ConstantExpression :
default :
 
*The labels come in front of a statement and multiple labels are permitted.
 
*The break statement allows to leave a switch statement. Syntax: break ;
 
*Layout according to our coding standard:

select ( Expression ) {
case Constant1:
   StatementSequence1a
   break;
 
case Constant2:
case Constant3:
   StatementSequence2
   break;
 
default:
   StatementSequence3
   break;
}

 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002