[Python-ideas] Break multiple loop levels

Chris Angelico rosuav at gmail.com
Sat May 11 23:21:13 EDT 2019


On Sun, May 12, 2019 at 1:16 PM David Mertz <mertz at gnosis.cx> wrote:
>
> Ok, sure. But what if different seen_enough() conditions are in the two inner loops? By "break to outer" ... I mean, don't get any more 'main' from 'stuff'. I meant to dig through some real code, but forgot because I was writing code for work. This example on my tablet is the general pattern I often need though. And obviously I've solved it one way or another hundreds of times.
>
> I think a "labelled break" would be nice though. It might have even been a past PEP.
>

This is why concrete examples are much easier to discuss, heh.

In any case, it's often possible to either (a) redefine the inner loop
as some sort of container operation, or (b) redefine the outer
operation as a function, and use "return". So it would be helpful to
have an example that CAN'T be rewritten in one of those ways, to use
as a compelling example.

ChrisA


More information about the Python-ideas mailing list