I. Break,continue,goto in Java
First break,continue is a keyword in Java, and Goto is a reserved word.
Based on the ghost performance of Goto in C and C + +, I think Goto may still be a long-term bench in Java.
Break: Forcibly exits the loop and does not perform subsequent steps in the loop.
Continue: Launch the current loop, go back to the starting point of the loop, start a new loop
Examples are as follows:
//ContinueSystem.out.println ("//continue:"); for(inti = 0; I < 10; i++) { if(i = = 5) { Continue; } System.out.print ("I=" + i + ""); } // BreakSystem.out.println ("\n//break:"); for(inti = 0; I < 10; i++) { if(i = = 5) { Break; } System.out.print ("I=" + i + ""); }
The results of the operation are as follows:
Two. labeled Double-loop and Break,continue
For a double-or multilayer-loop break label, it jumps directly to the label and interrupts all loops, while the continue label jumps to the label for a new loop.
Examples are as follows:
Out for(inti = 0; I < 5; i++) {in: for(intj = 0; J < 3; J + +) { if(i = = 3) { BreakOut ; } System.out.println ("I=" + i + "\ T" + "j=" +j); }} System.out.println ("#################################"); Out: for(inti = 0; I < 5; i++) {in: for(intj = 0; J < 3; J + +) { if(i = = 2) { ContinueOut ; } System.out.println ("I=" + i + "\ T" + "j=" +j); } }
Break and continue in Java and tags