for: else: - any practical uses for the else clause?

skip at pobox.com skip at pobox.com
Tue Sep 26 17:07:30 EDT 2006


    metaperl> I'm wondering if anyone has ever found a practical use for the
    metaperl> else branch?

Yeah, I use it from time to time:

    for foo in bar:
        if foo matches some condition:
            print "sail to tahiti!"
            break
    else:
        print "abandon ship!"
        
Skip



More information about the Python-list mailing list