switch case、 if else if、 for循环和do while循环的区别和用法

switch case、 if else if、 for循环和do while循环的区别和用法

1:switch case 通常处理精确值,进行一次条件判断后直接执行到程序的条件语句(代码如下)

switch case、 if else if、 for循环和do while循环的区别和用法

2:if else if 通常处理范围值,弊端(有几种条件就得判断多少次) ;
switch case、 if else if、 for循环和do while循环的区别和用法

​ 和switch case循环的区别:分支少的时候,if效率比switch高,分支多的时候,switch的效率高,而且结构更清晰。(代码如下)

3:一段代码重复的执行(代码如下)

switch case、 if else if、 for循环和do while循环的区别和用法

4:先执行一次循环代码,再执行条件表达式,结果为true,则继续执行循环体代码,如果为false,则退出循环,进入后面代码执行。
switch case、 if else if、 for循环和do while循环的区别和用法