[Tutor] nested loops

Alan Gauld alan.gauld at btinternet.com
Mon Feb 7 17:40:51 CET 2011


"Wayne Werner" <waynejwerner at gmail.com> wrote 

You probably want to add a sentinel to break out of the outer
loops too:

found = False
> highscore = 0
> alignment = somealignment
> for x in something and not found:
>      for y in somethingelse and not found:
>           for z in evenmoresomething:
>               if x+y+z > highscore:
>                   highscore = x+y+z
>                   alignment = newalignment
                     found = True
                     break

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list