breaking out of nested loop
rbt
rbt at athop1.ath.vt.edu
Tue Jul 12 10:59:49 EDT 2005
Thanks guys... that works great. Now I understand why sometimes logic
such as 'while not true' is used ;)
On Tue, 2005-07-12 at 10:51 -0400, Peter Hansen wrote:
> rbt wrote:
> > What is the appropriate way to break out of this while loop if the for
> > loop finds a match?
>
> Define a flag first:
>
> keepGoing = True
>
> > while 1:
> while keepGoing:
>
> > for x in xrange(len(group)):
> > try:
> ...
> > if match == target:
> > print "Collision!!!"
> > print make_string
>
> Set the flag here, then do the break:
> keepGoing = False
>
> > break
>
> Tada...
>
> -Peter
More information about the Python-list
mailing list