3 ms·
They are only equivalent to a very limited goto, not the unlimited sort that Dijkstra's letter was primarily about. A continue or break can be replaced with th
by Jtsummers 4y ago
They are only equivalent to a very limited goto, not the unlimited sort that Dijkstra's letter was primarily about.
A continue or break can be replaced with this:
while (some_cond) {
if (whatever) continue;
if (whocares) break;
}
=>
while (some_cond) {
next:
if (whatever) goto next;
if (whocares) goto after;
}
after: ...
EDIT: added break into the above, forgot to earlier
Note that it stays within the same scope or, in the case of a break, would just escape that scope. The sort of goto Dijsktra wrote about would let you do things like this:
void foo() {
while(some_cond) {
next: // how did we get here again?
...
}
}
void bar() {
goto next;
}