Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They probably used the word "else" to cut down on the number of reserved keywords, and for consistency with try / except / else.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: