The rap against "while True:" loops
greg
greg at cosc.canterbury.ac.nz
Mon Oct 12 04:36:34 EDT 2009
Mensanator wrote:
> while not done:
> ...
> if n==1: done = True
> ...
Seems to me that 'while not done:' is no better than
'while True:', because in both cases you have to look
inside the loop to find out what the exit condition
is.
Using a more meaningful name for the flag can help,
but you can't teach someone that just by giving them
an overly simplified rules such as "never use
while True:". They'll probably just replace it with
'while not done:' and think they've improved things,
without ever really understanding the issue.
--
Greg
More information about the Python-list
mailing list