Sujet : Re: Loops (was Re: do { quit; } else { })
De : rjh (at) *nospam* cpax.org.uk (Richard Heathfield)
Groupes : comp.lang.cDate : 15. Apr 2025, 13:51:59
Autres entêtes
Organisation : Fix this later
Message-ID : <vtlkpf$3mmqu$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
User-Agent : Mozilla Thunderbird
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.
-- Richard HeathfieldEmail: rjh at cpax dot org dot uk"Usenet is a strange place" - dmr 29 July 1999Sig line 4 vacant - apply within