The rap against "while True:" loops

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Wed Oct 21 01:00:19 EDT 2009


In message <haqq0p$7fn$1 at reader1.panix.com>, kj wrote:

> I use "while True"-loops often, and intend to continue doing this
> "while True" ...

My practice with regard to loops is to use constructs such as "while 
(condition) { ... }" and "do ... while (condition)" where "condition" is the 
ONLY terminating condition (i.e. no "break" statements in the middle). If I 
need to exit in the middle, or have more than one exit, then I switch to 
"for (;;) { ... }" or (Python)" "while True : ...". That way, anybody 
reading the code immediately realizes that the only way out of the loop is 
by one or more exits in the middle.

By the way, in practice some 90% of my loops seem to need either multiple 
exits or an exit in the middle.



More information about the Python-list mailing list