The GOTO statement is a reserved word in Java and is not implemented. However, in other languages (C), Goto is a valid keyword.
Although the break and continue supported in Java can implement the GOTO statement function, I personally summarize that their usage is similar.
First, the label requirements in Java are very strict.
The label must be in front of a loop, which means that the loop name is outer (assuming the label name is outer), and there cannot be any statement after this line;
Break and continue are used in combination with loop statements. Therefore, the use of statement labels is also closely integrated with loops.
When statement labels are used, they can only be defined before the loop iteration statement. Otherwise, the compilation fails.
Therefore, the break and continue with a label can only jump to the loop body or select the body (IF ).
The (c) goto rules are flexible, and the labels in (c) can be before any legal statement.
Therefore, Goto can jump anywhere in a function (C language) (of course, it cannot violate the rational usage of the GOTO statement, for example, it cannot jump between nesting)
Therefore, my personal summary
The break and continue with labels are limited to jump in the loop body.
The labeled goto can be redirected in the entire method (C language function ).
Goto is more flexible than break and continue with labels, because it is too flexible.
The logic structure of the program becomes complex, the process is not clear enough, and the readability of the program is reduced.
So the Goto is retained in Java.
The GOTO statement is a reserved word in Java and is not implemented. However, in other languages (C), Goto is a valid keyword.
Although the break and continue supported in Java can implement the GOTO statement function, I personally summarize that their usage is similar.
First, the label requirements in Java are very strict.
The label must be in front of a loop, which means that the loop name is outer (assuming the label name is outer), and there cannot be any statement after this line;
Break and continue are used in combination with loop statements. Therefore, the use of statement labels is also closely integrated with loops.
When statement labels are used, they can only be defined before the loop iteration statement. Otherwise, the compilation fails.
Therefore, the break and continue with a label can only jump to the loop body or select the body (IF ).
The (c) goto rules are flexible, and the labels in (c) can be before any legal statement.
Therefore, Goto can jump anywhere in a function (C language) (of course, it cannot violate the rational usage of the GOTO statement, for example, it cannot jump between nesting)
Therefore, my personal summary
The break and continue with labels are limited to jump in the loop body.
The labeled goto can be redirected in the entire method (C language function ).
Goto is more flexible than break and continue with labels, because it is too flexible.
The logic structure of the program becomes complex, the process is not clear enough, and the readability of the program is reduced.
So the Goto is retained in Java.