while (a=b()) ...

Vadim Chugunov chega at my-dejanews.com
Tue May 11 15:57:22 EDT 1999


Well, why don't we get radical and introduce a new loop type:

do1:
    <do stuff>
do2 <continuation condition>:
    <do more stuff>
[else:
    <after-loop stuff>] # for consistency

The original example could then be spelled as follows:
--------------
do1:
    c= curs.fetchone()
do2 c!=None:
    # do something with c
    print c
--------------
which is not redundant, less error-prone than while(a=b()) and more
elegant (IMHO) than while 1: ... if not <cond> break ...

Of course, I do not insist on using those particular keywords :-)))

Vadim

> >c=curs.fetchone()
> >while c:
> >    do something with c
> >    c=curs.fetchone()
> >
> >Is it a little redundant? Yes.  Error prone?  No.
>
> Error prone it is - by virtue of being redundant. changes to
> the loop may require changing two code lines, and it's easy
> to forget to update redundant code.
>
> while (c=curs.fetchone(); c):
>
> is not redundant, nor does it have the '=' != '==' problem.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




More information about the Python-list mailing list