I found the following example when goto might be a little useful: When to use Goto when programming in C. But “ Never Use GOTO ” was the first thing I learned at the university, and therefore I never used it (at least not in C, C ++, C #, Java, ...).
GOTO's biggest problem is that if you read a piece of the method, you don’t see where it could be called. For instance:
int a = 1; division: int b = 4 / a;
... sounds normal. But you wrote a 0-dividing failure if there is the following GOTO after the division block:
int a = 1; division: int b = 4 / a;
... Or null-exception fails if there is GOTO in front of the separation block:
goto division;
... this is just one example, GOTO leads to much more controversial situations. So, please forget about GOTO, and people (including you) will be happier to read your code.
Use a “return partnership”; instead of your goto's.
jing
source share