do...while

Michael P. Soulier msoulier at nortelnetworks.com
Thu Jun 20 14:12:31 EDT 2002


On Thu, Jun 20, 2002 at 10:42:56AM -0700, Sean 'Shaleh' Perry wrote:
> 
> On 20-Jun-2002 Michael P. Soulier wrote:
> >     Greetings.
> > 
> >     How do you people handle the lack of a do...while in Python? I find that
> > at times, I must initialize variables for a loop with identical code to the
> > loop, which feels like a waste to me. 
> > 
> > ie.
> > 
> >     line = filehandle.readline()
> >     while len(line) > 5:
> >         line = filehandle.readline()
> > 
> >     A do...while here would be nice. 
> > 
> >     Just curious. 
> > 
> 
> 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. 

    Mike

-- 
Michael P. Soulier, QX41, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix





More information about the Python-list mailing list