Sujet : Re: Loops (was Re: do { quit; } else { })
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.cDate : 21. Apr 2025, 00:19:37
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vu3ve9$21pgn$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
87ldruv65j.fsf@nosuchdomain.example.com>,
Keith Thompson <Keith.S.Thompson+
u@gmail.com> wrote:
...
I understand and completely accept that you find the while loop
clearer, and I have no interest in changing your mind.
>
I find the for loop clearer. I won't speak for anyone else, but I
suspect a lot of C programmers would also find the for loop clearer.
I'm with Bart on this one. I think "for" loops that aren't simple
iterations (i.e., do this thing 10 times), are harder to understand than
the equivalent "while" loop. I.e., this:
p = someComplexFunctionCall(this,that,the,other,thing);
while (p) {
do stuff;
p = getNewValue(p);
}
is a lot easier to understand at first glance than the equivalent:
for (p = someComplexFunctionCall(this,that,the,other,thing); p; p = getNewValue(p))
do stuff;
But, having said that, I'll always write the "for" version, because I like
writing compact (some would say "cryptic") code. Job security, and all that...
-- Meatball Ron wants to replace the phrase "climate change" with the phrase"energy dominance" in policy discussions.Yeah, like that makes a lot of sense...