On Thu, Jul 23, 2009 at 8:41 PM, Carlo Hamalainen<carlo.hamalai...@gmail.com> wrote: > > On Thu, Jul 23, 2009 at 12:31 PM, mac8090<bonzerpot...@hotmail.com> wrote: >> How does one break from a double for loop, or a loop of two variables? > > One way is to use an exception: > > > class GetOut(Exception): pass > > try: > for x in range(10): > for y in range(10): > if 2^x*3^y==12: > raise GetOut > except GetOut: > pass > > print x, y > > $ sage foo.sage > 2 1
Using exceptions to break out of multiple loops is discussed at this thread http://mail.python.org/pipermail/python-list/2002-January/123690.html -- Regards Minh Van Nguyen --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---