while (a=b()) ...

Magnus L. Hetland mlh at idt.ntnu.no
Wed May 19 07:13:40 EDT 1999


"Gordon McMillan" <gmcm at hypernet.com> writes:

> [Magnus whines]

Oh, yeah?! <wink>

> > >> Well ... IMNSHO, the while 1-idiom is just a symptom of too weak
> > >> control structures, or bad structuring of the code <wink>.

[...]

> > Or perhaps you could use
> > something like
> > 
> > while "x (aka somefile.readline) != None":

Well -- this sort of thing (as most other solutions) has been
suggested before...

> 
> > (Quick show of hands, how many people are using the construct
> >  while "some string": and think that it would break if the string
> >  were evaled at some point in the future?  How many of you expect
> >  most of your code to break for Python 2.0 anyways?)

Ah -- you mean that it should be eval'ed? Hm... Well... I guess
something like:

while "readline() != None":
    line = readline()
    if line == None: break
    process(line)

would be more readable than "while 1" anyway... And if you don't want
the unneccesary string processing, you might just use:

while 1: # While readline() is not None
    etc...

(Me, I'd be happy if there were boolean variables true and false...
while true seems more python-like than while 1 to me... Oh - I've
whined about this before <wink>)

> "Groundhog Day"-would-never-have-been-filmed-if-they'd-used
>  -a-for-loop-instead-of-a-while-ly y'rs

And your point is? <wink>

--

  Magnus
  Lie
  Hetland        http://arcadia.laiv.org <arcadia at laiv.org>




More information about the Python-list mailing list