[Python-ideas] Break multiple loop levels

Jonathan Fine jfine2358 at gmail.com
Sat May 11 13:33:24 EDT 2019


Dear Haael

With python you can write
    for i, j in something ():
        # loop body

This would cover both your examples.

For the first, use itertools.product. For the second, write a custom
iterator.

--
Jonathan


On Sat, 11 May 2019, 18:22 haael, <haael at interia.pl> wrote:

>
> Python allows for breaking out from a loop through 'break' and
> 'continue' keywords. It would be nice if it was possible to break many
> loop levels using one command.
>
> I propose two constructions for that:
>
> break
> break break
> break break break
> ...
>
> continue
> break continue
> break break continue
> ...
>
> And so on.
>
> Example:
>
> for i in range(10):
>      for j in range(10):
>          if i == 2 and j == 3:
>              break break
>
> for i in range(10):
>      for j in range(10):
>          if i == 2 and j == 3:
>              break continue
>          if i == 7:
>              break break
>
> Breaking out from many loops at once is a common practice, currently
> implemented through boolean testing and exceptions. This proposal would
> make it cleaner.
>
> _______________________________________________
> 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/28dda3dc/attachment.html>


More information about the Python-ideas mailing list