while (a=b()) ...

Jim Meier fatjim at home.com
Sat May 15 14:26:22 EDT 1999


Aahz Maruch wrote:

> In article <373DAF53.4287D726 at home.com>, Jim Meier  <fatjim at home.com> wrote:
> >> Aahz Maruch <aahz at netcom.com> wrote:
> >>>
> >>>   for line in f.readline()
> >>>     frobulate(line)
> >>>
> >
> >As was told to me previously, this *is* excellent, readable and usable..
> >But while it does solve the big, big "while 1"-is-not-an-infinite-loop
> >ugliness, the use of break is still involved instead of other, harder-edged
> >controls. I have no problem with this, I just felt like nit-picking to
> >recover my manliness. <whoops-blew-my-cover-style grin>
>
> How is break involved?
> --

As in, when you want to be done with processing before being finished iterating:
for tick_tick_tick in series_of_hardships:
    work_work(tick_tick_tick)
    work_work(tick_tick_tick)
    if revolution_is_ripe:
        break

(i had suggested

done=false
while not done:
    work
    if condition:
        done=true
    work

but that only breaks AFTER each iteration ( the intended purpose of while)
)

-Jim.





More information about the Python-list mailing list