4 ms·
break statements are goto statements with implicit labels! To really get rid of gotos, you'll need to have a loop control variable: ... int done = 0; wh
by groovy2shoes 13y ago
break statements are goto statements with implicit labels! To really get rid of gotos, you'll need to have a loop control variable:
...
int done = 0;
while (!done) {
...
done = 1;
...
}
Yes, it works fine and it's not terribly compelex. The version with goto is simpler because it's a more direct translation of the corresponding diagram.
- deleted 13y ago[deleted]
- dllthomas 13y agoAren't loops and ifs goto statements with implicit labels?
- groovy2shoes 13y agoHeh, I suppose you're right :)
- mtdewcmu 12y agoIf you want to find all the implicit gotos, just disassemble the compiled code. Your program will be littered with jmp instructions and the conditional versions of jmp. There's no getting away from them.
- groovy2shoes 12y agoYup, I know. I just got a little carried away :) My main point was similar to something you'd said earlier: > What we now know for absolute certain is that it's possible to write any kind of code without gotos (including awful code). I meant to point out the inverse, that it's possible to write good code even with gotos -- but it takes the same amount of care and diligence as writing good code in general. I don't mean to advocate the use of gotos, rather the elimination of the paranoia surrounding them.
- nitrogen 13y agoJust in case it's not clear, the break statements in my example are to break out of the switch(), not the while(). C's switch statements are like a computed goto.
- groovy2shoes 13y agoAh, right. I forgot about break inside switch. Thanks. You're right about the switch statements being like a computed goto, albeit a delimited, forward-only one. I still think it's silly to bend over backwards to avoid using goto in places where goto is a natural fit.