[Python-ideas] if condition: break idiom

Arnaud Delobelle arnodel at googlemail.com
Sun Sep 21 21:28:00 CEST 2008

On 21 Sep 2008, at 19:36, Terry Reedy wrote:

> Josiah Carlson wrote:
>>>> break if condition else continue
>>>> continue if condition else break
>>> No that would be silly.
>> Why?  It follows directly from conditional expressions
> In my view, backwards conditional expressions were Guido's worst  
> mistake.  This proposal and comments like the above partly  
> illustrate why I think so.

I don't know what was the motivation for including conditional  
expression in the language, but:

     condition and x or y

is better replaced with:

     x if condition else y

So from a pragmatic point of view, if-expressions work as some kind of  
"vaccine" against the above.


More information about the Python-ideas mailing list