3 ms·
The page linked has a good rule of thumb for the gotos: don't use backward ones. All the "escape" uses of goto - breaking out of loops, jumping to the appropria
by praptak 14y ago
The page linked has a good rule of thumb for the gotos: don't use backward ones. All the "escape" uses of goto - breaking out of loops, jumping to the appropriate part of the cleanup code, emulating exceptions behavior are forward jumps.
Back in the day hand coded assembly had jumps into the middle of functions' bodies which was a space-saving idiom for things like default initialization - the beginning of the function had some initialization code but you could jump into the function body (and skip this initialization block), provided that you did your own init and set the proper registers yourself.
- huhtenberg 14y agoThere is however one valid case for using backward gotos - it's the loop restart. again: for ( ..container.. ) { ... if ( ... ) { touch(container); /* * If touch() changes container in a contrived * way, then restarting the loop is sometimes * the cleanest option. */ goto again; } } This obviously requires caution to not enter an infinite loop, but that's usually easier to guarantee than to reconcile the consequences of touch().
- reycharles 14y agoJava has exactly this. It's called "labelled continue". again: for(...) { ... continue again; .... }