The rap against "while True:" loops

Mensanator mensanator at aol.com
Mon Oct 12 13:35:06 EDT 2009


On Oct 12, 3:36�am, greg <g... at cosc.canterbury.ac.nz> wrote:
> 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.

You're missing the point. It's not that you have to
look inside for the terminating condition. It's that
you don't need a break.

>
> --
> Greg




More information about the Python-list mailing list