[Tutor] while else, for else

Blake.Garretson@dana.com Blake.Garretson@dana.com
Mon, 14 Oct 2002 09:30:02 -0400


I have been using Python for 3+ years now, and I have yet to see regular
use of the "while else" or "for else" constructs.  I personally *never* use
them, and unless I haven't read enough source code from other people, I
haven't seen evidence that anybody else uses them very often either.

If you look in books like "Learning Python" or "Programming Python", you
can certainly find examples of how they can be used, but they never seem
necessary.  You can always get by with loops and normal if statments (and
some flags).

To me, it seems like they make the code more confusing and less readable,
so I don't use them.  So my question is, am I missing something?  Are there
situations that "while/for else" provide the only way to implement an
algorithm?  In other words, would I ever *have* to use it in order to do
something?  Moreover, are there common applications that maybe I *should*
be using this construct?  Are there any Python idioms that use loop elses?

Thanks,
-Blake Garretson