5 ms·
Depending on the specifics, an alternative is to break that "while(0)" loop into a function and use "return" instead of break. Even more of an alternative (and
by openasocket 9y ago
Depending on the specifics, an alternative is to break that "while(0)" loop into a function and use "return" instead of break.
Even more of an alternative (and would only be a good idea in certain circumstances) is, in a language with destructors, to make an object created at the top with a destructor for that last block of code, so you can throw out the loop and use return instead of break. This would also work with Golang defer statements. But again, only a good idea if that makes some sort of sense in your program, and isn't just a work around for the lack of gotos.
Gotos make me cringe, a "while(0)" hack makes me cringe just as much. The whole problem with goto is it confuses the reader as to where the control flow is going, but this is just as bad because until you read to the end you're under the impression those statements will be run multiple times.