1. Break
Break: Jumps out of the current loop, but if it is a nested loop, you can only jump out of the current layer of the loop, and only break through the layer to jump out of all loops;
for (int i = 0 ; I < 10 ; I++ if (i = = 6 ) { break ; // forces the loop to terminate when I==6 is executed, i==6 will not be executed } System. out .println (i); The output is 0 1 2 3 4 5 ; 6 will not output
2, continue
Continue: Terminates the current loop, but does not jump out of the loop (the statement following the continue in the loop will not be executed) and continues down the loop based on the loop condition.
for (int0; i++) {if6) { Continue; // i==6 will not be executed, but be interrupted . } System. out . println (i); }
The output is 0 1 2 3 4 5 7 8 9; only 6 no output
3. Return
(1). Return exits from the current method and returns to the statement of the method that was called to continue execution.
(2). Return returns a value to the statement that invokes the method, and the data type of the return value must match the type of the return value in the declaration of the method.
(3). Return can be followed without parameters, without parameters is returned empty, in fact, the main purpose is to interrupt function execution, return to the calling function.
Special Note: The return value of void method, from a certain judgment to jump, must use return;
The difference between break continue return in Java