19 program flow control

1, sequence control: program executed line by line from top to bottom, there is no intermediate judgment, and jump

2, branch control: the program to selectively execute

  ① single branch

    if (conditional expression) {

      Block of code;

    }

  ② double branch

    if (conditional expression) {

      1 block of code;

    }

    else {

      2 block of code;

    }

  ③ multi-branch

    if (conditional expression 1) {

      1 block of code;

    }

    else if (conditional expression 2) {

      2 block of code;

    }

    ....

    else {

      N-code block is executed;

    }

  ④ nested branch: In a branching structure and complete another branch nested structure, branched structure which is referred to as the inner branch, the branch structure outside of the outer layer is called a branch. Nested branch is not suitable too, up to no more than 3 layers.

  ⑤switch branch structure

    switch (expression) {

      Constant case 1:

      Statement block 1;

      break;

      Constant case 2:

      Statement block 2;

      break ;

      ...

      default :

      default statement block

      break ;

    }  

    switch statement expression is a constant expression must be an integer (char, short, int, long, etc.) or enumeration type

    Value case clause must be a constant, not a variable

    default clause is optional and, when no matching Case, performs default 

    After a break statement is used in case that the branch executing the program out of the switch statement block

    If you do not write break, the next case statement will execute a block, until it encounters a break or executed to the end switch, this phenomenon is called penetration

    switch and if the comparison:

      If it is determined the specific values ​​is small, and in line with integers, enumerated types, although both statements can be used, it is recommended to use a switch statement

      Other cases, the judgment of the interval, the result is true for the false judgment, that use is if, if the wider

 

Guess you like

Origin www.cnblogs.com/shanlu0000/p/12343225.html