zoukankan      html  css  js  c++  java
  • <C Primer Plus>12 switch and break continue

    #include <stdio.h>
    #define STOP '#'
    int main(void){
        char ch;
    
        printf("Please input the lower
    ");
        printf("input the # to stop.
    ");
        while ((ch = getchar()) != STOP){
            if (islower(ch)){
                switch (ch){
                case 'a':
                    printf("apple,a fruit of red.
    ");
                    break;
                case 'b':
                    printf("banan, a fruit of yellow.
    ");
                    break;
                case 'c':
                    printf("coati, recoonlike mammal.
    ");
                    break;
                case 'd':
                    printf("desman,aquatic molelike critter.
    ");
                    break;
                case 'e':
                    printf("echidna,the spiny anteater.
    ");
                    break;
                case 'f':
                    printf("fisher ,brownish marten.
    ");
                    break;
                }        
            }
            else{
                printf("I recongnize only lowercase letters.
    ");
            }
            
        }
        printf("Bye!
    ");
        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;

    }

  • 相关阅读:
    LIPS的历史
    语法分析生成器 LEX
    Effective JAVA 中有关Exception的几条建议
    Code Reading chap10
    Code Reading chap8
    Code Reading chap7
    Code Reading chap11
    Code Reading chap9
    软件设计中的抽象层次
    Invalid bound statement (not found) @Update注解写的怎么还报错!
  • 原文地址:https://www.cnblogs.com/michael2016/p/6665206.html
Copyright © 2011-2022 走看看