A clear two concepts
- Loop: Refers to the whole process of repeating an operation in accordance with the specified number of times; its key statements have a for, foreach, while, do, and
- Iteration: Refers to a single operation during a cycle, 1 cycles consisting of n iterations
Two usage induction
- Break jumps out of the current loop and ends this loop
- Continue stops the current iteration and returns to the beginning of the cycle, continuing with the next iteration
- Break label breaks all iterations and returns to the label, ending all loops currently in progress (both inner and outer loops are terminated)
- Continue label interrupts all iterations, returns to the label, restarts the next loop from the outer loop
Three examples
Public classLabeledfor { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub inti = 0; Outer: for(;true; ) {Inner: for(; i < ten; i++) {System.out.println ("I =" +i); if(2 = =i) {System.out.println ("Continue"); //i++; Continue; } if(3 = =i) {System.out.println ("Break"); I++; Break; } if(7 = =i) {System.out.println ("Continue inner"); I++; Continueouter; } if(8 = =i) {System.out.println ("Break Outer"); Breakouter; }}}}} Output result: I= 0I= 1I= 2ContinueI= 3 BreakI= 4I= 5I= 6I= 7ContinueInneri= 8 BreakOuter
Continue, break keyword usage for Java