Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Sun, 04 May 2025 13:52:48 -0700 Organization: None to speak of Lines: 52 Message-ID: <877c2wp07z.fsf@nosuchdomain.example.com> References: <87a58mqt2o.fsf@nosuchdomain.example.com> <20250413072027.219@kylheku.com> <20250415153419.00004cf7@yahoo.com> <86h62078i8.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 04 May 2025 22:52:49 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ed5558e6b5362a41777eb3e1b4d62403"; logging-data="2864406"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dg/0Nz6N5FulhJicQpimm" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:o4EnCop4B0BJguNabmFQLSIJKvk= sha1:fLkdsPMwp3Bfi8S0Lw6ISV2qAr0= Bytes: 3532 Tim Rentsch writes: > Michael S 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.com void Void(void) { Void(); } /* The recursive call of the void */