03: branch structure

if

Outline

Although the program order to solve the structure calculation, the output and so on, but can not make a judgment reselection.

For determination should first issue reselection is necessary to use a branched structure.

form

    Single branch

    if ( determination condition ) { satisfies the condition code }

 

    Multi-Branch

    if ( determination condition ) {

       Code meets conditions

    }else{

       Code does not meet the conditions

    }

 

    Nested branch

    if ( judgment condition 1) {

       Code 1

    } else if ( determination condition 2) {

       Code 2

    } else if ( determination condition 3) {

       Code 3

    } else if ( determination condition 4) {

       Code 4

    }else{

       Everyone does not meet code

    }

switch

Outline

When a case was established back from this case penetrate all case, including the default.

Until the end of the program or the program encounters a break until the end.

form

switch ( integer expression ) {

case 1 : syso(1);break;

case 2 : syso(2);

case 3 : syso(3);

case 4 : syso(4);

case 5 : syso(5);

……

default:syso(0);

}

Examples

Guess you like

Origin www.cnblogs.com/aqin1012/p/12127938.html