while expression feature proposal

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 24 17:34:05 EDT 2012


On Wed, Oct 24, 2012 at 2:40 PM, Dan Loewenherz <dloewenherz at gmail.com> wrote:
> So I'm sure a lot of you have run into the following pattern. I use it
> all the time and it always has felt a bit awkward due to the duplicate
> variable assignment.
>
> VAR = EXPR
> while VAR:
>     BLOCK
>     VAR = EXPR

The idiomatic way to do this is:

while True:
    VAR = EXPR
    if not VAR:
        break
    BLOCK



More information about the Python-list mailing list