Alan Gauld wrote:
"Wayne Werner" <waynejwer...@gmail.com> wrote
You probably want to add a sentinel to break out of the outer
loops too:
I don't think you want to break out of *any* of the loops. Otherwise you
will skip testing combinations. In your example, the first time you set
highscore and alignment, you break out of all three loops and only test
the first triple x,y,z.
> 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
That's the equivalent of a return in the innermost loop. If you're
looking for the *first* matching highscore, that's fine, but not if you
want the biggest.
--
Steven
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor