public class BreakCyc { //终止循环
public static void main(String[] args) {
System.out.println("中断单层循环");
int array[]={1,3,4,5,2,6,7,8,9};
System.out.println("array数组为");
for(int j=0;j<array.length;j++){
System.out.print(array[j]+" ");
}
System.out.println("\n"+"中断循环见2就停止输出");
for(int i=0;i<array.length;i++){ // int i:array 遍历数组
if(array[i]==2)
break;
System.out.print(array[i]+" ");
}
System.out.println("\n"+"用continue输出完数组");
for(int i=0;i<array.length;i++){
if(array[i]==2)
continue; //用continue继续输出,过滤2
System.out.print(array[i]+" ");
}
System.out.println("\n"+"中断双层循环");
int [][] brray={{61,80,62,63},{50,65,70,80},{66,66,50,90}};
System.out.println("见到不及格停止输出");
System.out.println("这次的考试成绩\n语文\t数学\t英语\t历史");
No1:for(int[] is : brray){ //遍历成绩表格
for(int i : is){
System.out.print(i+"\t");
if(i<60){
System.out.println("\n怎么有不及格的?");
break No1;
}
}
System.out.println();
}
}
public static void main(String[] args) {
System.out.println("中断单层循环");
int array[]={1,3,4,5,2,6,7,8,9};
System.out.println("array数组为");
for(int j=0;j<array.length;j++){
System.out.print(array[j]+" ");
}
System.out.println("\n"+"中断循环见2就停止输出");
for(int i=0;i<array.length;i++){ // int i:array 遍历数组
if(array[i]==2)
break;
System.out.print(array[i]+" ");
}
System.out.println("\n"+"用continue输出完数组");
for(int i=0;i<array.length;i++){
if(array[i]==2)
continue; //用continue继续输出,过滤2
System.out.print(array[i]+" ");
}
System.out.println("\n"+"中断双层循环");
int [][] brray={{61,80,62,63},{50,65,70,80},{66,66,50,90}};
System.out.println("见到不及格停止输出");
System.out.println("这次的考试成绩\n语文\t数学\t英语\t历史");
No1:for(int[] is : brray){ //遍历成绩表格
for(int i : is){
System.out.print(i+"\t");
if(i<60){
System.out.println("\n怎么有不及格的?");
break No1;
}
}
System.out.println();
}
}