The rap against "while True:" loops

Paul Rubin http
Mon Oct 12 21:16:51 EDT 2009


kj <no.email at please.post> writes:
> I use "while True"-loops often, and intend to continue doing this
> "while True", but I'm curious to know: how widespread is the
> injunction against such loops?  Has it reached the status of "best
> practice"?

E. W. Dijkstra used to advocate that every loop have exactly one entry
point and exactly one exit point, i.e. no multiple break statements.
This is probably a misstatement, but I believe that the purpose was to
be able to specify a precondition at the loop entrance and a
postcondition at the exit, and be able to verify the conditions more
straightforwardly than if there were multiple exit points.  But, that
doesn't specifically seem to speak against "while True:".  For
example, Ada has a loop construct where the test and break is in the
middle of the loop.



More information about the Python-list mailing list