[Python-ideas] Break multiple loop levels

David Mertz mertz at gnosis.cx
Sat May 11 17:20:23 EDT 2019


I don't love the 'break break' syntax idea. But I find myself wanting to
break out of nested loops quite often. Very rarely could this be
transformed to an 'itertools.permutation' de-nesting, albeit perhaps more
often than I actually do that.

My usual kludge is a sentinel 'break_outer' variable that gets set back and
forth between True and False working the loops. Usually work a name that
descriptive of the actual domain of the code.

On Sat, May 11, 2019, 1:40 PM Paul Moore <p.f.moore at gmail.com> wrote:

> On Sat, 11 May 2019 at 18:22, haael <haael at interia.pl> wrote:
> > Breaking out from many loops at once is a common practice
>
> Do you have evidence for this? In my experience, it's very rare
> (although I concede it would be *occasionally* convenient).
>
> In most cases where I'd consider breaking out of multiple levels of
> nested loop, I've tended to find that it's probably more readable to
> refactor the code to use a generator, or something like that.
> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190511/bc2ea90e/attachment.html>


More information about the Python-ideas mailing list