Why is not it used?
For the obfuscation of the code it implies.
For example, in a loop ( do
, while
, for
), we can be sure that the only way out is in the loop itself; either because the necessary condition was met, or because we use a break
.
We can then check the code backwards , knowing that to reach an exact point, obligatorily has gone through the previous points (taking into account the if( ) ... else ...
, of course).
This is not true in goto
. If we find a tag, a destination for a goto
, there is no way to know the sequence of instructions that got us there. Where we come from ? Above all, if we make our code a swatch of goto
.
What happens in the program when it is used?
Exactly what you expect: you jump to the indicated label. There are no major side effects, or anything bad implicit in using it, except as indicated in the previous paragraph. If you are in a block { ... }
, the local variables to the block cease to exist and, if you are in C ++, the destructors are called correctly; everything works as expected.