Lupus590, on 15 March 2016 - 09:26 PM, said:
There
are instances in where a goto would be the
best way to proceed. The fact that it's
missing forces coders to write spag when those instances occur: so it was for good reason that it was added to 5.2.
Let's say you've built a cluster of nested loops that goes however many levels deep. For whatever reason you need to break out of them when a certain condition is met.
Under 5.1, you've got two options: either perform your conditional check within each and every loop (as each "break" can only exit one at a time), let the loops all run their course, or turn the entire cluster into a redundant function so you can return from it. All of these solutions are sub-optimal.
Goto allows you to simply exit out of the loop structure. Boom, problem solved.
That said; yes, it's the sort of statement that coders often misuse. That does not, however, make it a bad thing in itself.