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.