break:终止,中断循环
public class test{
public static void main(String[] args){
for(int x = 0;x<=5;x++){
if(x ==3){
System.out.println(x);
break;/当条件满足时,终端程序
}
}
}
}
/*
Desktop\test>java test
3
*/
public class test{
public static void main(String[] args){
for(int x = 0;x<=5;x++){
if(x ==3){
break;//当条件满足时,终端程序
}
System.out.println(x);
}
}
}
/*
0
1
2
*/
重点:
public class test{
public static void main(String[] args){
int x = 1; //在循环外声明变量
int y =1;
for(;x<=5;x++){
for(;y<=5;y++){
if(y ==3){ //循环时取到的变量是累积赋值过后的变量,也就是第2轮循环x,y分别为&#