<C Primer Plus>12 switch and break continue

#include <stdio.h>
#define STOP '#'
int main(void){
    char ch;

    printf("Please input the lower\n");
    printf("input the # to stop.\n");
    while ((ch = getchar()) != STOP){
        if (islower(ch)){
            switch (ch){
            case 'a':
                printf("apple,a fruit of red.\n");
                break;
            case 'b':
                printf("banan, a fruit of yellow.\n");
                break;
            case 'c':
                printf("coati, recoonlike mammal.\n");
                break;
            case 'd':
                printf("desman,aquatic molelike critter.\n");
                break;
            case 'e':
                printf("echidna,the spiny anteater.\n");
                break;
            case 'f':
                printf("fisher ,brownish marten.\n");
                break;
            }        
        }
        else{
            printf("I recongnize only lowercase letters.\n");
        }
        
    }
    printf("Bye!\n");
    return 0;
}

REMEBER:

1 continue causes the rest of an iteration to be skipped and the next iteration to be started.

2.break causes the program to break free of the loop that encloses it and to proceed to the next stage of the program.

3 swtich(integer expression1){

  case constant1:

      statements

      break;//depend on your meaning 

  case constant2:

      statements

      break;

  default:

      statements

      break;

}

posted @ 2017-04-04 15:58  Micheal_you  阅读(175)  评论(0编辑  收藏  举报