Chapter 5: C Control Flow
case ‘B’ :
DobB();
switch( input){
23();
break;
default:
DoDefault();
Switch nd a frequent source of head boinking bugs
(one where you boink your head for being dumb enough to leave out a break
break;
case ‘0’ :
case ‘1’ :
case ‘2’ :
case ‘3’ :
Gofer0123();
break;
case ‘4’ :
case ‘5’ :
case ‘6’ :
case ‘7’ :
Gofer4567();
break;
default:
DoDefault();
break;
}
This can be compacted as:
case ‘a’ : case ‘A’ :
DoaA();
break;
case ‘b’ : case ‘B’ :
DobB();
break;
case ‘0’ : case ‘1’ : case ‘2’ : case ‘3’ :
Gofer01
case ‘4’ : case ‘5’ : case ‘6’ : case ‘7’ :
Gofer4567();
break;
break;
}
statements are error prone a