switch (controlling expression)
{ 
   case a:
   case b:
   statements;
   break;
   case c:
   statements;
   break;
   default:
   statements;
}
a, b, c are called “case labels”. They can only be a constant, or a character represented by ‘a’ or ‘A’. When “switch” statement is executed, the case labels are one by one compared with the controlling expression. When one is equal to the expression, all the statements after that case label will be executed, until meeting one “break” statement. So putting different labels together simply means “OR”.
If a “default:” label is put, when no case label is matched, the statements after the “default:” label is executed. It is not a must but a good practice to always put a “default” label even if you are absolutely sure your program is free of bugs.
A “break” statement is not required after the “default” case if it is at the last.


Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates