[CentralOH] Breaking Out Of Nested Loops

Travis Risner deeptinker at gmail.com
Thu Jul 7 22:10:26 EDT 2016


Hi Jim,

T Python Pocket Reference book describes the function of the break 
statement and goes on to say "...Hint, raise and try statements can be 
used to exit multiple loop levels." nothing more.

I wrote a program to test it out.  It is available at

https://github.com/deeppunster/deep-punster/blob/master/play_break.py

HTH,
Travis

On 7/6/16 11:02 PM, jep200404 at columbus.rr.com wrote:
> On Wed, 6 Jul 2016 18:03:04 -0400, jep200404 at columbus.rr.com wrote:
>
>> James Prior presented:
>>
>>      A technique for breaking out of nested loops
>>      by using a generator to yield tuples of values.
>>
>>          http://nbviewer.jupyter.org/github/cohpy/challenge-201605-generators/blob/master/james-prior/b-break-out-of-nested-loops.ipynb
>
> Travis Risner mentioned a technique using try and raise
> from "Python Pocket Reference" by Mark Lutz.
>
> I am guessing that the nested loops would be inside a try
> clause and a raise statement would be used instead of
> a break. What is the recommended exception to raise?
> Does putting nested loops inside a try clause
> rub PEP8 the wrong way?
>
> Travis, what does the book say?
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>


More information about the CentralOH mailing list