3 ms·
There is however one valid case for using backward gotos - it's the loop restart. again: for ( ..container.. ) { ... if ( ... )
by huhtenberg 14y ago
There 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; .... }