for what are for/while else clauses

Aahz aahz at pythoncraft.com
Sat Nov 22 14:12:02 EST 2003


In article <258fd9b8.0311220938.3210484c at posting.google.com>,
Magnus Lyck? <magnus at thinkware.se> wrote:
>
>On the other hand, I only think it's in the case of a break
>in block that...
>
>while condition:
>    block
>else:
>    print "Loop finished"
>
>...will behave differently than...
>
>while condition:
>    block
>print "Loop finished"
>
>So, unless you use a break in the block, the else statement is just
>noise: an extra line of code and additional whitespace for the
>following statement(s).

While technically correct, I don't think you could claim that it's "just
noise" in this example:

        try:
            for ORlist in includes:
                try:
                    for filter in ORlist:
                        for field in curr_fields:
                            for item in record[field]:
                                if match(item, filter):
                                    raise Found
                    else:
                        raise NotFound
                except Found:
                    continue
        except NotFound:
            continue
        else:
            result.append(record)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.




More information about the Python-list mailing list