Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch 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> References: <87a58mqt2o.fsf@nosuchdomain.example.com> <20250413072027.219@kylheku.com> <20250415153419.00004cf7@yahoo.com> 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 Richard Heathfield writes: > On 15/04/2025 13:34, Michael S wrote: > > > >> 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 %