Deutsch   English   Français   Italiano  
<877c2wp07z.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
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: <vspbjh$8dvd$1@dont-email.me> <vtbc6o$1te2o$1@dont-email.me>
	<vtbhjv$24api$1@dont-email.me> <vtbn2k$293r1$1@dont-email.me>
	<vtc19j$2kqlj$1@dont-email.me>
	<87a58mqt2o.fsf@nosuchdomain.example.com>
	<vtc7mp$2q5hr$1@dont-email.me> <vtcqf6$3j95s$1@dont-email.me>
	<vtdh4q$b3kt$1@dont-email.me> <vtf7fe$1qtpg$1@dont-email.me>
	<vtgfuf$31ug1$1@dont-email.me> <20250413072027.219@kylheku.com>
	<vtgpce$39229$1@dont-email.me> <vti2ki$g23v$1@dont-email.me>
	<vtin99$vu24$1@dont-email.me> <vtiuf0$18au8$1@dont-email.me>
	<vtj97r$1i3v3$1@dont-email.me> <vtl166$36p6b$1@dont-email.me>
	<vtlcg0$3f46a$2@dont-email.me> <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 <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.com
void Void(void) { Void(); } /* The recursive call of the void */