The common control execution flow has if-else; iterative while,do-while,for,foreach;return;break,continue;
tags used in conjunction with break,continue; switch; in the thinking in Java Chapter,
There are two places that have been re-recognized and shared with you.
1, return has two functions, 1. Sets the return value of a method; 2. Exits the current method.
So any method can use the return statement, and using return in the Void method is
Use return to exit the current method's role.
And there is no return statement in the method that returns void, at the end of the method there is an implicit
The return.
2, and break,continue with the use of the label to achieve the role of Goto.
1. The general continue will return to the beginning of the most inner loop (top) and continue execution.
2. The tagged continue will reach the position of the label and re-enter the loop immediately following the label.
3. A normal break breaks and jumps out of the loop that the label refers to.
4. A tagged break breaks and jumps out of the loop that the label refers to.
It is important to note that the only reason to use tags in Java is because there is a loop nesting, and you want to get from multiple layers of nesting
Break and continue.
Introduce code snippets from thinking in Java to learn about:
public class Labeldemo {public static void main (string[] args) {int i = 0;outer:for (; True;) {inner:for (; i <; i++) {System.out.println ("i =" + i), if (i = = 2) {System.out.println ("continue"); continue;} if (i = = 3) {System.out.println ("break"); i++;break;} if (i = = 7) {System.out.println ("continue outer"); i++;continue outer;} if (i = = 8) {System.out.println ("break outer"), Break outer;} for (int k = 0; k < 5; k++) {if (k = = 3) {System.out.println ("continue inner"); Continue inner;}}}}}
The label of the notation for the signature plus ":", in multiple nested loops, continue tagging, indicating the next loop to enter the tag followed by the loop (similar to the continue in a single-layer loop, the difference is the loop after the label); break tagging, Indicates a loop that follows a direct jump out of the label (like a break in a single-layer loop, the difference is the loop that follows the tag).
Java control execution Process--thinking in Java learning