2 ms·
It is consistent with the idea that it provides an alternative clause to a failing loop guard. Using the much clearer C syntax as pseudo-code, suppose we have
by kazinator 8y ago
It is consistent with the idea that it provides an alternative clause to a failing loop guard.
Using the much clearer C syntax as pseudo-code, suppose we have this:
for (;;) {
if (loop_guard()) {
body;
} else {
alternative;
break;
}
}
We can imagine an extension to while which lets us rewrite it like this:
while (loop_guard()) {
body;
} else {
alternative;
}
Based on this framing, there is justification in calling it else.
The runs counter to an intuition which would like it to be this:
if (loop_guard()) {
while (loop_guard()) {
body;
}
} else {
alternative;
}
I.e. not an alternative in the face of the failed loop guard on every iteration, but just the first loop guard test: an alternative to the loop when no iterations take place.