if:
对具体值进行判断
对区间结果进行判断
对运算结果是布尔boolean类型的进行判断
swith:
对具体数值进行判断
值得个数是固定的,对于几个固定的值进行判断建议使用swith语句 因为switch会将具体的答案加载到内存会效率相对于高一点
while(条件表达式){
执行语句
}
public class TestWhile {
public static void main(String [] args){
/*循环语句
* while(条件语句) {
* 执行语句
* }
*
*/
int x =1;
while(x <3){
System.out.println("x="+x);
x++;
}
}
}
do while用法:
/* do
* {
*执行语句
* }while(条件语句)
*
*/
int y =2;
do {
System.out.println("y="+x);
}
while(y<4);
}