breaking out of nested loop

Duncan Booth duncan.booth at invalid.invalid
Tue Jul 12 11:02:29 EDT 2005


rbt wrote:

> What is the appropriate way to break out of this while loop if the for
> loop finds a match?
> 
> while 1:
>     for x in xrange(len(group)):

another option not yet suggested is simply to collapse the two loops into a 
single loop:

import itertools

for x in itertools.cycle(range(len(group)):
   ... as before ...



More information about the Python-list mailing list