[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: Loops Up: Selection Previous: if

switch

...
// switch is like a multiple 'if'. 
// The values that the switching variable is compared with
// have to be constants, or `default'.

switch(i){
case 1: printf("i is one\n");
        break; // if break wasn't here, this case will
               // fall through into the next.
case 2: printf("i is two\n");
        break;
default: printf("i is neither  one nor two\n");
        break;
}
...



Tim Love
2001-07-05