why no break N levels, as in other leading languages?

Aahz aahz at pythoncraft.com
Fri May 2 15:30:53 EDT 2003


In article <mailman.1051839783.7607.python-list at python.org>,
Skip Montanaro  <skip at pobox.com> wrote:
>
>Also, if you need to break out of a triply nested loop you may want to
>consider an algorithm redesign anyway. ;-)

"May", yes.  Consider this bit from my TextDB module:

        try:
            for ORlist in includes:
                try:
                    for filter in ORlist:
                        for field in curr_fields:
                            for item in record[field]:
                                if item.lower().find(filter) >= 0:
                                    raise Found
                    else:
                        raise NotFound
                except Found:
                    continue
        except NotFound:
            continue
        else:
            result.append(record)

I think it's pretty nifty that I figured out how to use overlapping
exceptions (combined with else) to avoid tracking how many matches there
are in a series of ANDed conditions.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles:  boring syntax, unsurprising semantics,
few automatic coercions, etc etc.  But that's one of the things I like
about it."  --Tim Peters on Python, 16 Sep 93




More information about the Python-list mailing list