Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32068

Re: while expression feature proposal

References <CAOKWLrERVuT-u=9YZGnQUhWLv2M6F06pU20vG9W1joD9h-SdSQ@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-24 15:34 -0600
Subject Re: while expression feature proposal
Newsgroups comp.lang.python
Message-ID <mailman.2797.1351114478.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Oct 24, 2012 at 2:40 PM, Dan Loewenherz <dloewenherz@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: while expression feature proposal Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-24 15:34 -0600

csiph-web