To play around with the goto statement, I've rewritten a while loop in a more assembly-style loop:
// while
int i=0;
while (i++<10)
printf("%d...", i);
// asm-ish
loop:
i++;
printf("%d...", i);
if (i<10)
goto loop;
loop_exit:
return 0;
Outside of a sort of academic exercise, are there any real-world/useful examples of how the goto statement can be used? Or is this basically a vestigial part of c that isn't used.
Here's an example of a code file that makes extensive use of it: https://github.com/postgres/postgres/blob/ca3b37487be333a1d241dab1bbdd17a211a88f43/src/port/snprintf.c.
I suppose one thing I can think of is getting out of deep-nesting without having to use a bunch of continue/breaks, but that's about it.