如下代码为何还会执行for循环,明明for循环在case 30里面呀?
public class Test {
public static void main(String args[]){
int x = 40;
switch( x ){
case 10:
System.out.print("Value of X is 10");
break;
case 20:
System.out.print("Value of X is 20");
break;
case 30:
System.out.println("Value of X is 30");
for(;x<=50;){
x++;
}
//break;
case 40:
System.out.println("Value of X is 40");
//break;
case 50:
System.out.println("Value of X is 50");
//break;
default:
System.out.println("这是 default 语句");
}
System.out.print("x=" + x);
}
}
我复制你的代码之后的运行结果,case 30: 并没有执行
Value of X is 40
Value of X is 50
这是 default 语句
x=40请按任意键继续. . .
我照着你的代码写了 没有进入循环
可能当时是你运行有点问题吧!