3 ms·
The only times I've really wanted goto were around exception handling. Java (not sure if it started there or was borrowed) actually has a construct that can do
by dehrmann 6y ago
The only times I've really wanted goto were around exception handling. Java (not sure if it started there or was borrowed) actually has a construct that can do this without the issues with goto:
block: {
...
if (err){ break block; }
...
if (err){ break block; }
....
}
- svrb 6y agoRust has this innovative feature called "functions" which enables you to break from any block by just giving it a name and using "return". It can even return a value! (/s obviously, but also not /s obviously. The serious point here may be that Java or whatever got in the way of defining functions by requiring them to be "methods" stuck in a "class" rather than, you know, just functions.)
- pirocks 6y agoA static function in Java is essentially just a function. Also I have no idea what functions being associated with classes has to do with breaking out of loops.
- gpderetta 6y agoencapsulate your nested loops in a function and return to exit multiple loops at the same time. Having nested lightweight functions allows minimal syntactical overhead compared to plain loops, although still not zero.