public static void main(String[] args) throws Exception {
for....{
test();
}
}
public void test(){
if(...){
//在这终止循环
}
}
...收起
public static void main(String[] args) throws Exception { for....{ boolean flag = test(); if(flag){ break; } } }public boolean test(){ boolean flag = false; if(...){ //在这终止循环 flag = true; } return flag;}
...全文
在main方法和test方法外部定义一个boolean变量,这个变量一定要在main方法和test方法外部定义; static boolean stop=false; public static void main(String[] args) throws Exception { for....{ if(stop){
...全文