C Case Structure Examples
Switch (toupper(property_code))
{
case ‘R’ :
commission_rate = 0.060;
break;
case ‘M’ :
commission_rate = 0.050;
break;
case ‘C’ :
commission_rate = 0.045;
break;
default :
printf(“\nInvalid Property Code! Try Again.”);
break;
}
The break statement is required in C because as soon as a case condition is satisfied the statements following will be executed and then control will continue to fall thru and all other statements following conditions will be executed. The break statement sends control immediately to the end of the block of code.