Loop-and-a-half (Re: Curious assignment behaviour)
Michael Abbott
michael at rcp.co.uk
Fri Oct 12 03:00:56 EDT 2001
Donn Cave <donn at u.washington.edu> wrote in
news:9q4it9$tio$1 at nntp6.u.washington.edu:
> I sort of regret wasting bandwidth on this purely academic question,
> but it's a matter of truly venerable tradition that C's loop is a
> bit shy of perfection. The idea as I understand it, is that there
> are essentially two control points in a loop, the entry, and the
> conditional repeat. C conflates those two in one, because both
> entry and the conditional repeat have to be at the "top".
Perhaps it's worth recalling at this point the syntax used by Algol68 for a
loop. This was really quite pretty and possibly slightly relevant:
WHILE
statements;
expression
DO
statements
OD
Of course, in C this needs to be translated to:
while(1)
{
statements;
if (!expression) break;
statements;
}
and in Python we have to do exactly the same:
while 1:
statements:
if not expression: break
statements
<Shrug> It's not pretty, but I'd rather worry about having a conditional
expression (off topic; we've already beaten that to death and not quite
managed a PEP out of it...)
More information about the Python-list
mailing list