Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #393138

Re: Loops (was Re: do { quit; } else { })

Path csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Loops (was Re: do { quit; } else { })
Date Sun, 04 May 2025 07:40:30 -0700
Organization A noiseless patient Spider
Lines 33
Message-ID <86cyco782p.fsf@linuxsc.com> (permalink)
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> <vtlkpf$3mmqu$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Date Sun, 04 May 2025 16:40:30 +0200 (CEST)
Injection-Info dont-email.me; posting-host="f2e2a4892b4200c8deca4768c4473856"; logging-data="2179137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DF4Qs7MTv1dg4uk+qZ0OgzeHS3ec6wpI="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:RYdiEsdqk8q0bcnOzVqpNytYOPE= sha1:UWx4n72NCK3ZMwR6JA4UVq4shpo=
Xref csiph.com comp.lang.c:393138

Show key headers only | View raw


Richard Heathfield <rjh@cpax.org.uk> writes:

> On 15/04/2025 13:34, Michael S wrote:
>
> <snip>
>
>> 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?
>> In the hindsight, probably a mistake.
>
> In hindsight:
>
> $ find . -name \*.c | xargs cat | wc -l
> 126343
> $ find . -name \*.c | xargs grep -w while | wc -l
> 556
> $ find . -name \*.c | xargs grep -w for | wc -l
> 1258
>
>
> So although I use for() about twice as much as I use while(), I still
> find while a better option one time in three.  That's useful enough to
> make it worth keeping in the toolbox.

Out of curiousity, I tabulated a similar set of statistics for
a recent C project.  Considering just the three iteration
control structures (do/for/while), the results (rounded to the
nearest 0.1 percent) were

   while      56.1 %
   for        24.1 %
   do/while   19.5 %

Back to comp.lang.c | Previous | Next | Find similar


Thread

Re: Loops (was Re: do { quit; } else { }) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-04 07:40 -0700

csiph-web