Re: breaking out of nested loop

2005-07-13 Thread Raymond Hettinger
[rbt] 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)): try: mix = random.sample(group, x) make_string = ''.join(mix) n = md5.new(make_string) match

breaking out of nested loop

2005-07-12 Thread rbt
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)): try: mix = random.sample(group, x) make_string = ''.join(mix) n = md5.new(make_string) match =

Re: breaking out of nested loop

2005-07-12 Thread Fuzzyman
You either need to set a marker flag with multiple breaks - *or* (probably more pythonic) wrap it in a try..except and raise an exception. Define your own exception class and just trap for that if you want to avoid catching other exceptions. There is no single command to break out of multiple

Re: breaking out of nested loop

2005-07-12 Thread Peter Hansen
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

Re: breaking out of nested loop

2005-07-12 Thread rbt
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:

Re: breaking out of nested loop

2005-07-12 Thread Duncan Booth
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

Re: breaking out of nested loop

2005-07-12 Thread Steven D'Aprano
On Tue, 12 Jul 2005 10:19:04 -0400, rbt wrote: What is the appropriate way to break out of this while loop if the for loop finds a match? Refactor it into something easier to comprehend? And comments never go astray. (Untested. And my docstrings are obviously bogus.) def

Re: breaking out of nested loop

2005-07-12 Thread Jeremy Sanders
rbt wrote: What is the appropriate way to break out of this while loop if the for loop finds a match? queue discussion why Python doesn't have a break N statement... -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list

RE: breaking out of nested loop

2005-07-12 Thread Tim Golden
[Jeremy Sanders] | rbt wrote: | | What is the appropriate way to break out of this while loop | if the for | loop finds a match? | | queue discussion why Python doesn't have a break N statement... pedantry Presumably you meant cue discussion... /pedantry (Ducks runs) TJG

Re: breaking out of nested loop

2005-07-12 Thread Andrew Koenig
rbt [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] What is the appropriate way to break out of this while loop if the for loop finds a match? Make it a function and use a return statement to break out. -- http://mail.python.org/mailman/listinfo/python-list