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 {
}
Case: LabeledFor.java
 
  1. A plain continue goes to the top of the innermost loop and continues.
  2. A labeled continue goes to the label and re-enters the loop right after that label.
  3. A break "drops out of the bottom" of the loop.
  4. A labeled break drops out of the bottom of the end of the loop denoted by the label.

Next Page