do...while

Peter Hansen peter at engcorp.com
Thu Jun 20 21:43:47 EDT 2002


"Michael P. Soulier" wrote:
> 
> On Thu, Jun 20, 2002 at 10:42:56AM -0700, Sean 'Shaleh' Perry wrote:
> > while 1:
> >     line = filehandle.readline()
> >     if len(line) <= 5: break
> >     ....
> >     ....
> >
> > is a typical way to implement it.
> 
>     Right, I've used that in the past. It doesn't seem nearly as clean though,
> as making the conditions for terminating the loop plain in the loop
> declaration. Considering the Python community's leaning towards readable code,
> necessitating a break for code factoring goes against that philosophy.

Avoiding duplicated code always trumps an uneasy feeling that
the code might not be as pretty as it could be in another
language or with new language constructs...

Once you get over that uneasy feeling, and implement the loop
that way a few times, and focus on maintainability, you'll
probably stop worrying about it.  At least, I did. :)

-Peter



More information about the Python-list mailing list