用break;或者continue; 两者的区别就看下面的例子吧 //break1.java public class break1 { public static void main(String args[]){
for (int i=0;i<5;i++){ if (i==3) break; System.out.println("the number is"+i); } for (int i=0;i<5;i++){ if (i==3) continue; System.out.println("the number is"+i); } } }结果: the number is0 the number is1 the number is2 the number is0 the number is1 the number is2 the number is4
return;
....
两者的区别就看下面的例子吧
//break1.java
public class break1 {
public static void main(String args[]){
for (int i=0;i<5;i++){
if (i==3) break;
System.out.println("the number is"+i);
}
for (int i=0;i<5;i++){
if (i==3) continue;
System.out.println("the number is"+i);
} }
}结果:
the number is0
the number is1
the number is2
the number is0
the number is1
the number is2
the number is4
....
}
一旦条件不满足就不执行,换句话说就是一旦条件满足就执行,太简单了吧
class hello{
if(condition){
...
}
run(){}
...}
condition后面的语句中包括一条语句使得不再运行hello这个类。
试试这个如何
1、返回为void的用return类就用System.exit(int)。
1、返回为void的
用return;
2、返回不是void的
用return xx;
类就用System.exit(int)。