Return
1. Return Value of the method (no void return value)
2. Exit the current method and return the value
Break
1. Control the cyclic process
2. The break forcibly exits the loop and does not execute the remaining statements in the loop.
Continue
1. Control the cyclic process
2. Stop the iteration of the current loop, return to the starting point of the loop, and start the next iteration.
Label followed by a colon identifier
Lable:
Continue and break usually only interrupt the current loop. If they are used with tags, the loop will be interrupted and reach the tag location:
Package com. JavaTest;
Public class LabledFor {
Public static void main (String [] args ){
Int I = 0;
Outer:
While (true ){
System. out. println ("outer while loop ");
While (true ){
I ++;
System. out. println ("I =" + I );
If (I = 1 ){
System. out. println ("continue ");
Continue;
}
If (I = 3 ){
System. out. println ("continue outer ");
Continue outer;
}
If (I = 5 ){
System. out. println ("break ");
Break;
}
If (I = 7 ){
System. out. println ("break outer ");
Break outer;
}
}
}
}
}
Program Execution output:
Outer while loop
I = 1
Continue
I = 2
I = 3
Continue outer
Outer while loop
I = 4
I = 5
Break
Outer while loop
I = 6
I = 7
Break outer
1) continue will return to the beginning (top) of the innermost loop and continue execution
2) The continue with tags will reach the tag location and re-enter the loop next to the tag.
3) The break is interrupted and jumps out of the current loop.
4) The labelled break will interrupt and jump out of the loop indicated by the tag.
The only reason for using tags is that a nested loop exists and you want to use break or continue from the nested
This article is from the "bit by bit on the IT Road" blog