Sujet : Re: Loops (was Re: do { quit; } else { })
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 04. May 2025, 21:52:48
Autres entêtes
Organisation : None to speak of
Message-ID : <877c2wp07z.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Tim Rentsch <
tr.17687@z991.linuxsc.com> writes:
Michael S <already5chosen@yahoo.com> writes:
[...]
I suspect that 'while' loop is here in C because Dennis Ritchie wanted
'do .. while() ' and thought that if the keyword is here anyway than
why not reuse it?
>
According to K&R, all of the basic control structures in C -- if,
while, for, do, and switch (and listed in that order) -- were
provided in BCPL, though not using the same syntax as in C,.
K&R1 does say that. K&R2 dropped that statement.
BCPL's equivalent of C's do/while did not reuse the WHILE keyword.
From K&R1 :
C provides the fundamental flow-control constructions required
for well-structured programs: statement grouping; decision
making (if); looping with the termination test at the top
(while, for), or at the bottom (do); and selecting one of a
set of possible cases (switch). (All of these were provided
in BCPL as well, though with somewhat different syntax; that
language anticipated the vogue for "structured programming"
by several years.)
Today being Star Wars Day, I'll say that this is true "from a certain
point of view". The statement in K&R1 is accurate, but it could be
misinterpreted to imply that BCPL had an equivalent to the C-style
for loop. The BCPL for-command had two forms:
FOR N = expression1 TO expression2 BY constant-expression
DO command
and
FOR N = expression1 TO expression2 DO command
BCPL also had:
WHILE expression DO command
command REPEATWHILE expression // like C's do/while
UNTIL expression DO command
command REPEATUNTIL expression
command REPEAT // an infinite loop
Of course you could write the equivalent of a C-style for loop
using other constructs.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */