snailface wrote:It's actually a good way to break out of multiple nested loops instead of spamming 'break' statements. It's a lot less confusing.
I totally disagree. Is it less confusing to fill the whole code with labels? I don't think so. If you think so, then why even use functions? In which case, why even use C when you can use assembly?
Personally I've never used goto
statements because I have gotobreakphobia.
The problem comes mostly with error handling as codestation points out. AFAIK C does not provide any decent way for error handling, so you might use goto
for such things (although that would look like Visual Basic's On Error Goto
horrible source of bugs...). IMHO even assembly has better error handling than C (using sofwtare interrupts for example). I personally prefer to use codestation's nightmare "returning an error code from functions that fail". On other languages you have more decent designs to deal with errors (like Java's exceptions).
Resuming: IMHO you can use goto
if there's no decent subsitute for it, or if you think it will make the code more readable and maintainable. Anyway, try to keep it to a minimum.