3 ms·
Goto has its place. It's not evil, but should be used judiciously. After all, C family constructs such as break, continue are glorified/specialized, albeit scop
by hermitdev 7y ago
Goto has its place. It's not evil, but should be used judiciously. After all, C family constructs such as break, continue are glorified/specialized, albeit scoped and unlabelled gotos.
One of the places I like gotos is when I need to break out of a nested loop. A goto to outside of the outer loop is far more obvious than a flag and a conditional to break from the parent nested loop. It also generates better machine code and uses fewer registers, at least in debug mode.
Sure, goto can be abused, just like every other language construct. They have their time and place, though.
- mrighele 7y agoThe issue was not the presence of goto itself, but the fact that is was one of the main tools for flow control, while as you say it should be used sparingly. It is like having an army of soldiers armed with a David Crockett[1] instead of a regular rifle. Things may get ugly fast. [1] https://en.m.wikipedia.org/wiki/Davy_Crockett_(nuclear_device) https://en.m.wikipedia.org/wiki/Davy_Crockett_(nuclear_devic...