您的位置:首页 > 产品设计 > UI/UE

Break And Continue Of Java

2009-07-27 13:52 405 查看
Break And Continue

×A plain continue gose to top of the
innermost loop and continue.
×A labeled continue gose to the label
and re-enter the loop right after that
label.
×A break "drop out of the bottom" of
the loop.
×A labeled break drops out of the bottom
of the end of the loop denoted by the label.

Case:LabeledFor.java
//Break和Continue是带标号的
//LabeledFor

public class LabeledFor{
public static void main(String[] args){
int i=0;
outer:/*相当于C中的loop,
1、java中限制在loop后不可在加其他东西
2、此loop必须在某循环语句前
3、下面这一循环的名字叫outer,给循环命名*/
for(;true;){
inner:
for(;i<10;i++){
System.out.println("i="+i);
if(i==2){
System.out.println("Continue");
continue;}
if(i==3){
System.out.println("continue inner");
continue inner;//跳出inner循环,只可用于跳出
}
if(i==4){
System.out.println("break outer");
break outer;//跳出outer循环,只可用于跳出
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: