2/8/00
COM1100 Winter2000 Yuhong Yin
8
switch statement
n switch ( expression )
n{ // start of the compound statement
ncase value_1 :
n statement 1;
n break;
ncase value_2 :
n statement 1;
n break;
n …
ncase value_n :
n statement n;
n break;
ndefault :
n statement;
n} // end of  the compound statement
It provides an alternative to if-else chain for cases to compare the value of an integer expression to a specific value.
switch statement uses 4 C++ keywords :
• switch
• case
• break
• default