[Python-ideas] Break multiple loop levels

Elias Tarhini eltrhn at gmail.com
Sun May 12 04:36:28 EDT 2019


If I may propose `break n` as a replacement for the original message's
`break break ... break`, where n>0 is the number of contiguous loops to
break out of and `break 1` is synonymous with `break`. Seems easier on my
eyes/noggin than counting out the individual `break` statements.

Eli

On Sat, May 11, 2019, 10:21 AM 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/20190512/326bbae1/attachment.html>


More information about the Python-ideas mailing list