3.4.1 Break 和 continue
在任何循环体内,可以用break和continue来控制循环的流程。
break用来退出循环,而continue则用来放弃体内剩余的语句,进行下一轮循环。
Case: BreakAndContinue.java
臭名昭著的 "goto"
The goto keyword has been present in programming languages from the beginning.
标签是后面跟着一个colon的标识符, 象这样:
label1:
唯一能放置标签的地方是在一条循环语句前.
label1:
outer-iteration {
inner-iteration {
//�
break; // 1
//�
continue; // 2
//�
continue label1; // 3
//�
break label1; // 4
}
}
Case: LabeledFor.java
-
A plain continue goes to the top of the innermost loop and
continues.
-
A labeled continue goes to the label and re-enters the loop
right after that label.
-
A break "drops 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.