why no "do : until"?

Greg Jorgensen gregj at pobox.com
Sun Dec 31 02:49:38 CET 2000

I don't have any problem with Python's flow control statements, but it seems
a lot of people would like something equivalent to C's "do ... while" (or
"do ... until" if that turns you on). Logically the "while ... if ... break"
construction can handle anything, but the idiom stretch a bit thin. When
reading well-written C, "while (1)" or "for (;;)" means "loop an unknown
number of iterations," and "do ... while" means "loop at least one
iteration." If Python had a "do ... while" loop, some programmers could
write clearer code. It's not world peace, but it's something.

Some people don't like using the "break" statement to get out of a
loop--perhaps bad memories of BASIC and unpredictable loop index values.
They'll have to get over it. Python does have the (somewhat unusual) "else"
statement that can attach to "for" and "while" loops, in case the programmer
must distinguish between the loop running to completion or terminating by
"break." I haven't needed the "while ... else" (or "for ... else")
construction, probably because C doesn't have it and I think in C.

Greg Jorgensen
Deschooling Society
Portland, Oregon, USA
gregj at pobox.com

More information about the Python-list mailing list