I. Roles and differencesThe effect of break is to jump out of the current loop block (for, while, do, or block (switch). The function in the loop block is to jump out of the loop body that is currently circulating. The function in the block is the comparison between the interrupt and the next case condition. The Continue is used to end the execution of subsequent statements in the loop body and to jump back to the beginning of the loop block to perform the next loop instead of immediately looping the body.second, other usesBreak and continue can be used with statement labels. This is very simple, the following to a comprehensive example, to see the understanding:
/** * Created by IntelliJ idea. * User:leizhimin * date:2007-11-29 * TIME:15:47:20 * * public class Test {public static void main (String args[]) { Test test = new test (); TEST.TESTBREAK1 (); Test.testcontinue1 (); TEST.TESTBREAK2 (); Test.testcontinue2 (); }/** * Test continue * Continue used to end this loop */public void testContinue1 () {System.out.println (" --------test continue-------"); for (int i = 1; I <= 5; i++) {if (i = = 3) continue; System.out.println ("i=" + i); }}/** * Break is used to end the entire loop body */public void TestBreak1 () {System.out.println ("--------Test break1- ------"); for (int i = 1, i <= 5; i++) {if (i = = 3) break; System.out.println ("i=" + i); }}/** * Test a tagged break statement * Tags can only be written before the loop body, by the way, learn about the definition and use of statement tags in Java */public void TestBreak2 () { System.out.println ("--------Test break2-------"); int i = 1; int k = 4; Lable1:for (; I <= 5; i++, k--) {if (k = = 0) break lable1; System.out.println ("i=" + i + "; k= "+ k); }} public void TestContinue2 () {System.out.println ("--------test continue2-------"); lable1:for (int i = 1; i < ten; i++) {lable2:System.out.println ("i=" + i); for (int j = 0; J <; J + +) {if (j = = 9) continue lable1; } } } }Operation Result:--------Test BREAK1-------
I=1
i=2
--------Test Continue-------
I=1
i=2
I=4
I=5
--------Test BREAK2-------
I=1; K=4
i=2; K=3
i=3; k=2
i=4; K=1
--------Test continue2-------
I=1
i=2
I=3
I=4
I=5
I=6
I=7
I=8
I=9
Process finished with exit code 0 reference: Use of tags in Java http://blog.csdn.net/whiteotiger/article/details/6522261
Here's a summary of this usage:
(1) A simple continue will return the beginning of the most inner loop (top) and continue execution.
(2) The labeled continue will reach the position of the label and re-enter the loop immediately following the label
(3) Break breaks the current loop and moves away from the end of the current label.
(4) A tagged break breaks the current loop and moves away from the end of the loop indicated by that tag.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Summary of use of break and Continue keywords in Java