The jump statements in Java use Break, continue, and tags to perform their functions individually or in combination.
Today, I encountered a topic on the label naming specification, and by the way the jump statement syntax has been read, very rewarding.
In the book "Java Programming Ideas", the author explains in detail that the case code is now written below:
Public classLabeledfor { Public Static voidMain (string[] args) {intI=0; Outer: for(;true;) {inner: for(; i<10;i++) {System.out.println ("I=" +i); if(i==2) {System.out.println ("Continue"); Continue; } if(i==3) {System.out.println ("Break"); I++;//Otherwise I never gets incremented Break; } if(i==7) {System.out.println ("Continue outer"); I++;//Otherwise I never gets incremented Continueouter; } if(i==8) {System.out.println ("Break Outer"); Breakouter; } for(intk=0;k<5;k++){ if(k==3) {System.out.println ("Continue inner"); Continueinner; } } } } }}
See the results of the operation:
I=0continue inneri=1continue inneri=2continuei=3 break i=4continue inneri=5continue inneri=6Continue inneri=7continue outeri=8 break outer
The more important thing to think about is thatbreak interrupts the for loop and is before the end of the for loop, that is, the increment expression will not execute. Continue does not skip incrementing statements.
Similarly, in this case, when i==7, the continue outer statement jumps to the top of the loop and also skips the increment.
If there is no break outer, there is no way to jump out of the outer loop from inside the loop. this is because the break itself interrupts only the inner loop (continue is the same).
If you want to interrupt and exit at the same time, simply use a return.
Use of jump statements such as break, continue, and tags in java [top]