else clauses in while and for loops

Nick Maclaren nmm1 at cus.cam.ac.uk
Sat Apr 15 05:19:02 EDT 2000


In article <38F79B93.B03F0A6B at mindspring.com>,
Chuck Esterbrook  <echuck at mindspring.com> wrote:
>So did anyone present, in this thread, an example that shows a real need?

Whether or not they have one, there is a fairly common case:

    Perform an action XXX provided that no member of sequence YYY
fulfils a particular criterion.

Yes, you can also use exceptions for this, but the 'else' construct
is clearer and probably more efficient.

Actually, I would prefer a different way of doing this, but that is
another matter.  Python is Python and not some other language.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the Python-list mailing list