Goto was risky and it was one big name on some BBS back in the day that pushed for a “never use goto” dogma, rather than figuring out rules for when it should or shouldn’t be used. And a whole bunch of people just jumped on that bandwagon, but not everyone.
The main rule for using goto that I’m aware of is to never use it to jump into the middle of a scope. Jumping around in the same scope is fine, jumping out of a scope is fine (assuming you handle unwinding the stack correctly, which I think the C compiler tries to do, at least, but there are other constructs that can save/restore stack contexts to do the same thing as a goto but safer).
Though programming language contstructs can also help eliminate the cases where using goto gives better code. Breaking out of nested loops is the main good case for goto that I’m aware of. Without a goto, you need to set up an exit flag and check it before starting a new iteration for each loop level you want to escape from. Unless your language supports labelled breaks/continues, in which case the compiler knows which loop the break/continue refers to instead of needing to always assume it means the deepest level.
C/C++ is my favourite language, but I’ve used an enhanced C++ with labeled loops and it was nice.
Goto was risky and it was one big name on some BBS back in the day that pushed for a “never use goto” dogma, rather than figuring out rules for when it should or shouldn’t be used. And a whole bunch of people just jumped on that bandwagon, but not everyone.
The main rule for using goto that I’m aware of is to never use it to jump into the middle of a scope. Jumping around in the same scope is fine, jumping out of a scope is fine (assuming you handle unwinding the stack correctly, which I think the C compiler tries to do, at least, but there are other constructs that can save/restore stack contexts to do the same thing as a goto but safer).
Though programming language contstructs can also help eliminate the cases where using goto gives better code. Breaking out of nested loops is the main good case for goto that I’m aware of. Without a goto, you need to set up an exit flag and check it before starting a new iteration for each loop level you want to escape from. Unless your language supports labelled breaks/continues, in which case the compiler knows which loop the break/continue refers to instead of needing to always assume it means the deepest level.
C/C++ is my favourite language, but I’ve used an enhanced C++ with labeled loops and it was nice.