1.break //break作用范围:要么是switch语句,要么是循环语句。
xiaoa:for(int x=1;x<=5;x++) //此代码运行到break xiaoa;时就会直接结束。由此可知,break后加上指定的for循环,它就会跳出此循环。
{
xiaob:for( int y=1;y<=4;y++)
{
System.out.println("x="+x);
break xiaoa;
}
}
2.continue //continue 继续。结束本次循环,继续下次循环。只能运行于循环结构。
for(int x=0; x<3 ;x++) //本次运行结果为错误。
{ //如果continue单独存在时,下面不要有任何语句,因为执行不到。
continue;
System.out.println(“x=”+x )
}
for ( int x=0 ; x<11 ; x++) //本次运行结果为 1 3 5 7 9
{
if(x%2==0)
continue;
System.out.println("x="+x);
}