How to break out of two nested for loops?

Francois Petitjean littlejohn.75 at free.fr
Mon Jan 21 16:40:18 EST 2002


In Interpreter.py :
import Command   # another module
...
class Interpreter:
...
    def interpret(self,lines):
        """decode statement lines (list of strings) and run associated
action"""
        if lines[-1] == '':  del lines[-1]
        line = '\n'.join(lines)
        ret = None
        for module in self.lModules:
            for cde in module.lcdes:
                ret = cde.match(line)
                if ret:
                    break   # break 2 ??
            if ret:                #  or  else: continue   and a break
                break
        else:
            print "No command found to match '%s'\n" % (line,)
            return
        cde,m = ret   # line matches cde with parameters m
        if not self.quiet:
            if len(lines) < 7:
                toprint = lines
            else:
                toprint = lines[:3].append("...").append(lines[lines[-2:])
            print "%s\n %s '%s'" % ('\n'.join(toprint), cde.cmdMacro(),
cde.name)
        if not self.dry_run:
            cde.execute(m, lines[1:,-1])

A simple solution would be to have a nested function  interp_i  with
  ret = self.match(line)
  if ret: return ret







More information about the Python-list mailing list