Re: clever exit of nested loops

2018-09-27 Thread Gregory Ewing
Neal Becker wrote: but it does violate the principle "Exceptions should be used for exceptional conditions). Python doesn't really go in for that philosophy. Exceptions are often used for flow control, e.g. StopIteration. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: clever exit of nested loops

2018-09-27 Thread Thomas Jollans
On 2018-09-26 21:06, Mark Lawrence wrote: > > To me the Ned Batchelder presentation > https://www.youtube.com/watch?v=EnSu9hHGq5o "Loop like a Native" is the > definitive way on how to deal with loops in Python. > Hear, hear. Great talk. -- https://mail.python.org/mailman/listinfo/python-list

Re: clever exit of nested loops

2018-09-27 Thread Neal Becker
Christian Gollwitzer wrote: > Am 26.09.18 um 12:28 schrieb Bart: >> On 26/09/2018 10:10, Peter Otten wrote: >>> class Break(Exception): >>> pass >>> >>> try: >>> for i in range(10): >>> print(f'i: {i}') >>> for j in range(10): >>> print(f'\tj: {j}') >>> for k in range(10): >>> print(f'\t\tk:

Re: clever exit of nested loops

2018-09-27 Thread Christian Gollwitzer
Am 26.09.18 um 12:28 schrieb Bart: On 26/09/2018 10:10, Peter Otten wrote: class Break(Exception): pass try: for i in range(10): print(f'i: {i}') for j in range(10): print(f'\tj: {j}') for k in range(10):   

Re: clever exit of nested loops

2018-09-27 Thread John Ladasky
On Wednesday, September 26, 2018 at 12:50:20 AM UTC-7, vito.d...@gmail.com wrote: > I have "abused" the "else" clause of the loops to makes a break "broke" more > loops I did this once upon a time. In recent years, when I start writing tricky nested loops, I frequently find myself reaching

Re: clever exit of nested loops

2018-09-26 Thread Mark Lawrence
On 26/09/18 08:50, vito.detul...@gmail.com wrote: Hi Today I've added a couple of lines in my source code, and I'm very ashamed of it. it "runs", and I know what it does (for now), but it's "too clever". I have "abused" the "else" clause of the loops to makes a break "broke" more loops

Re: clever exit of nested loops

2018-09-26 Thread Peter Otten
vito.detul...@gmail.com wrote: > Hi > Today I've added a couple of lines in my source code, and I'm very ashamed > of it. it "runs", and I know what it does (for now), but it's "too > clever". I have "abused" the "else" clause of the loops to makes a break > "broke" more loops > > > for i

Re: clever exit of nested loops

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 5:56 PM wrote: > > Hi > Today I've added a couple of lines in my source code, and I'm very ashamed of > it. > it "runs", and I know what it does (for now), but it's "too clever". > I have "abused" the "else" clause of the loops to makes a break "broke" more > loops > > >