I have recently been asked if there is any goto in Java. The answer is yes. But Java will goto be the most reserved word, and in fact it is not intended to be used in language (as the person thinks).
Then someone will ask, no Goto, that Java is not the interruption of the sentence (narcissism, who will ask you, slag).
NO. NO. NO. Some. The Java designer added a break statement in the language to implement the interrupt program.
Here's a look at two ways to use the break in Java. (Why are two kinds of ...?) ...... Don't tell you now ... Look down ... )。
The first use of break
The code is as follows:
int i = 0;
while (true) {
if (i = =) {break
;
}
System.out.printf (i + "");
i++;
}
Run Result:
0 1 2 3 4 5 6 7 8 9 Break second usage
The code is as follows:
Jump: for
(int i = 0; i < 1000. i++) {for
(int j = 0; j < 1000; j) {
System.out.println (j);
if (j = = ten) {Break Jump}}}
Run results
0 1 2 3 4 5 6 7 8 9 10
The above is the two implementations of break in Java. (Have a look at it.) Ha ha ... )