[Java Basics] Loop structure 3
Break with continue interrupt loop ...
1 /**2 file path: G:\JavaByHands\ Loop statement3 file name: Breaktest.java4 Write Time: 2016/6/125 Author: Zheng-hui6 Write a description: Break end loop7 Break is completely out of the loop ~ ~ that is, encounter break loop termination ~ ~8 */9 Ten Public classbreaktest{ One A Public Static voidMain (string[] args) { - - //write A For loop the for(inti = 0; I < 10; i + + ) { - -System.out.println ("i =" +i); - + //terminating a loop with break - //judging the size with = = all wrong many times + if(i = = 5 ){ A at Break; - - } - - } - in //It's good to read more books . - //use tags to end all loops ... Inside, the outer layer ends together. to //Outer Loop + //Add a label - outer: the for(intj = 0; J < 10; J + +) { * $ //Inner LoopPanax Notoginseng for(intk = 0; K < 10; K + +) { - theSystem.out.println ("j =" + J + "; k =" +k); + A //end loop at specified place the if(j = = 1 && k = = 5) { + - Breakouter; $ } $ - } - the } - Wuyi } the -}
1 /**2 file path: G:\JavaByHands\ Loop statement3 file name: Continuetest.java4 Write Time: 2016/6/125 Author: Zheng-hui6 Write a note: Continue end this cycle7 Continue is the end of the cycle ~ and then the loop continues ~ ~8 */9 Ten Public classContinuetest { One A Public Static voidMain (string[] args) { - //Create a loop - for(inti = 0; I < 10; i + +) { the -System.out.println ("i =" +i); - - //Add a Continue + if(i = = 5) { - + Continue; A at } - -System.out.println ("i + 1 =" + (i + 1)); - - } - in //Like break , continue can use the label control to end the entire outer layer, the inner loop ~ ~ and then continue ~ - //label to ABC: + //outside - for(intj = 0; J < 3; J + +) { the //inside * for(intk = 0; K < 3; K + +) { $System.out.println ("j =" + j + "; K = "+k);Panax Notoginseng //conditions - if(k = = 2) { the ContinueABC; + } A theSYSTEM.OUT.PRINTLN ("------"); + } - } $ $ - } -}
[Java Basics] Loop structure 3