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 earlierNote 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;
}They're all wrappers around goto with various amounts of safety in their handling.
Some implementations are more safe than others ( https://www.php.net/manual/en/control-structures.break.php still gives me the heebie jeebies thought it was worse in older versions where the number could be a variable rather than an integer literal https://web.archive.org/web/20140312123653/https://www.php.n... )
Sure, you can express a for-loop in terms of goto. But when you read a for-loop, there are many things you're guaranteed won't happen that could with a goto. In that sense, it takes less attention to make a good for-loop. And a for-loop iterating over a collection also takes less attention than one with a manually-crafted iteration check.
That's the whole point of the article: lower-level instructions should be wrapped in higher-level instruction, more specialized and with less footguns.