Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    I know nothing about Arduinos but do a lot of desktop and server development. There is one acceptable usage (IMHO) for gotos and that's to break out of nested loops, it's much cleaner and easier to understand than the alternatives. Commented Jul 13, 2017 at 11:44
  • 1
    If you think goto's are evil, check out Linux code. Arguably, they are just as evil as try...catch blocks when used as such. Commented Jul 13, 2017 at 12:59
  • gotos aren't evil. They are used in production, professional C code all the time for error handling, including in safety-critical real-time software for life-saving devices, aircraft, etc. They just have to be used properly is all, and their usage pattern is limited and well-defined. Additionally, to keep the project MISRA-compliant, if that's something the project cares about, the usage pattern of gotos in the project must be documented as an exception, which is commonly done in MISRA-compliant software. Commented Aug 11, 2020 at 0:49
  • Here's some examples I wrote showing reasonable goto usage: stackoverflow.com/a/54488289/4561887. I've added additional references to justify their usage at the bottom of the answer. Of course, no code cannot be done without goto (ie: all code can be done withOUT goto), but many instances of code are greatly benefited and made more readable by properly using goto. Some professional teams even mandate the usage of goto in a standardized way in order to have cleaner, more-readable code. It's all about tradeoffs. Commented Aug 11, 2020 at 0:52