No Do while/repeat until looping construct in python?

John Roth johnroth at
Wed Mar 12 13:20:49 CET 2003

"Lars W" <lw at> wrote in message
news:b4mcsf$b5f$1 at
> Hello!
> Why is there no do-while looping construct in Python?
> It seems to me that such a feature is very useful. Consider the
> following pseduocode:
> <code>
> while i<j:
> <code>
> Compared with an imaginary do-while loop like in C or Pascal:
> do:
> <code>
> while i<j
> Alternatively, the imaginary code could be written:
> repeat:
> <code>
> until i>=j
> <code> might be a large chunk of code which has to be run at
> least once before the evaluation of "i<j" is made. But Python
> forces you to write code on the first form.
> I might be missing something, but do-while is indeed a
> useful looping construct which users would benefit from using.

Without attempting to channel Guido, I expect that there are a
number of reasons.

1. Python tends toward minimalism; there is usually lots of
resistance to adding constructs when there isn't a real clear
use case, and there are real clear and useful alternatives.
See the debate (aka "flame war") over PEP 308.

In this connection, the 'break' statement will handle the
case where you actually want the loop condition at the end,
at the expense of less than a half dozen additional keystrokes.

2. Python tends toward stating things clearly; that is, up front.
Putting the loop condition at the end is nowhere near as clear
as putting it up front.

3. Many of the actual use cases for a 'decision at the end'
loop are also served by the for statement, generators and

John Roth

> Regards
> Lars
> lw at

More information about the Python-list mailing list