Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #393138

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

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Loops (was Re: do { quit; } else { })
Date 2025-05-04 07:40 -0700
Organization A noiseless patient Spider
Message-ID <86cyco782p.fsf@linuxsc.com> (permalink)
References (16 earlier) <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>

Show all headers | 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