if and switch

Today, the editor will share with you the branch structure. Commonly used are "if" and "switch". Their syntaxes are respectively

if (condition) {

                 statement block 1

}else{

                statement block 2

}


switch(expression) {

 case constant 1:

                   statement;

                   break;

 case constant 2:

                   statement;

                   break;

default;

                    statement

}

They have the same point that they can implement multi-branch structure, the difference is that switch intelligently handles the conditional judgment of equal value, and the condition is the equivalent judgment of integer or character variable. Multiple ifs also include other if structures in the else part, which are especially suitable for situations where a variable handles a certain interval.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325890186&siteId=291194637