alan.gauld at btinternet.com
Sat Nov 17 09:41:38 CET 2007
"Michael" <python at mrfab.info> wrote
> This has probably been asked before but can I get some clarification
> why Python does not have a repeat...until statement,
Because Guido didn't put one in
repeat/until is never needed it is only ever a nice to have.
Indeed some languages don't even have a for loop for the same
reason (Oberon being an example). Some don't even
have any explicit loops since recursion can be used
instead - some Lisp dialects for example.
The important concept here is looping not the syntax
of the loop structure. However in Python the space
sensitive nature of the language does make a do/while
style loop a little harder to implement without breaking
good indentation practice. For example:
# code here
# more code
Now the until is visually part of the block - not nice!
(And if your school board don't understand that then
they have much bigger problems to worry about than
the syntax of loops!)
Is better structure but completely inconsistent with
every other Python construction (aside from try/except?)
You could of course introduce block markers to define
the block in the manner of Tcl or ruby etc but that too
would be completely inconsistent with Python style.
So instead we have the common Python idiom of
if condition: break
> repeat...until is bad practice?
No, just a variation on a theme that Python does not support
directly. There are plenty other loop structures that Python
(and other languages) does not support, for example ADAs
loop with exit:
exit when condition
But again that can be modelled using while/break
> a langauge must have a test last structure in it to be considered.
That's a bizarre requirement that rules out many significant
languages from which important lessons can be learnt.
As a matter of interest, how would they view COBOL which
has many more loop constructs than Python but they are all
done via a single command(PERFORM) which requires the
body of the loop to be a list of functions (aka paragraphs
PERFORM paragraph val TIMES
PERFORM paragraph VARYING variable FROM val BY val UNTIL condition.
PERFORM paragraph IF condition
PERFORM paragraph until condition
We can also modify these case to use
WITH TEST BEFORE or WITH TEST AFTER
clauses. All very powerful but very different syntactically from
Also, do they have any requirements on languages to support
functional programming constructs or anonymous functions/blocks?
All very important concepts.
Author of the Learn to Program web site
More information about the Tutor