do...until wisdom found...

Dennis Baker drbaker at softhome.net
Tue Apr 17 16:51:32 EDT 2001


On Tue, 17 Apr 2001 18:37:46 GMT "Fredrik Lundh" <fredrik at pythonware.com> wrote:

) Dennis Baker wrote
) > )         while 1:
) > )             set up for this cycle
) > )             if c: break
) > )             whatever needs to be done
) >
) > That's a product of poor design.  I consider it a failure to
) > resort to this sort of construct.
) 
) since your comment makes no sense at all to me,
) maybe you could elaborate?

I suppose this is a product of my Structured Programming coursework,  I simply
avoid constructs like this.  I was taught that loops and functions should have 
one entry point and one exit point.  Techniques that have served me well for a 
long time and make for more readable, easier to debug code.  For Example the 
construct above could be rewritten:

set up for first cycle
while !c:
   whatever needs to be done
   set up for next cycle

Works just as well and makes the code easier to read.  Usually you need to do 
slightly different stuff the first time through a loop anyhow.  I would guess 
it would also guess that it is (marginally) faster because it doesn't need to 
do the bogus test at the beginning of the loop.

Generally this works for me,  Your Mileage may vary.

) 
) Cheers /F
) 
) 
) -- 
) http://mail.python.org/mailman/listinfo/python-list
) 




More information about the Python-list mailing list