On Dec 4, 2019, at 14:56, Oscar Benjamin <[email protected]> wrote:
> 
> My suggestion would be to use a
> function rather than exceptions:
> 
> stuff = [10, 20, 30]
> other_stuff = [1, 2, 3]
> 
> def func():
>    for x in stuff:
>        for y in other_stuff:
>            print(x, y)
>            if x + y > 21:
>                return
> 
> func()
> 
> In this example it might seem awkward to introduce a function just for
> this but normally in context the function can have a more reasonable
> purpose and a good name and return something useful etc.

I think the majority of the time, refactoring it into a function actually makes 
it better, or at least neutral.

The problem is that occasionally it really does make it significantly worse, 
and that’s when you really wish named break existed.

But I think two people already said that’s about once/year for them? That 
sounds about right to me, too.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/5CK6L6R5E5MBZQHDWDVRVWJLGXVZV4VD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to