switch statement

   
switch statement Multibranch selection statement

  statement  := switch (  condition  )  statement   condition  ::=  expression   type-specifier-seq   declarator  =  assignment-expr  

The switch statement evaluates condition and saves the value. It compares the value to each case label in statement (which is typically a compound statement). The statements that follow the matching case label are executed. If no case label matches, the statements following the default label are executed. If there is no default , execution continues with the statement following the end of the switch statement.

All case labels in statement must be unique. Use the break statement to exit the switch statement at the end of each case.

Example

  switch  (c) { case '+':   z = add(x, y);   break; default:   z = noop(  );   break; }; 

See Also

break , case , declarator , default , expression , if , statement , type , Chapter 4

   


C++ in a Nutshell
C++ in a Nutshell
ISBN: 059600298X
EAN: 2147483647
Year: 2005
Pages: 270
Authors: Ray Lischner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net