3 ms·
Any time I have felt the need for something like goto, I have found that need served well by a function with multiple return statements. You're right that it ca
by quietbritishjim 8y ago
Any time I have felt the need for something like goto, I have found that need served well by a function with multiple return statements. You're right that it can't simulate jumping into a block though, but that seems like a feature to me. Also, refactoring the necessary portion of code into a function is usually an improvement in its own right.
It's funny that the GP comment mentioned this but the other comments have all focused on break/continue. I suppose the backward jumps you mention are usually only served by something like break/continue. But I find that when beginners are starting to learn to program, they very often ask for something that sounds a lot like a goto, but their need is also always satisfied by a function with multiple returns (which usually involves explaining what a function is).