Sujet : Re: Loops (was Re: do { quit; } else { })
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 19. Apr 2025, 20:54:15
Autres entêtes
Organisation : None to speak of
Message-ID : <8734e4nd08.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
[...]
I don't understand why you're happy using a crippled looping
mechanism, that is a PITA to use for the majority of iterating loops,
just so you have that flexibility for the whacky loops that are in the
minority, most of which can be trivially expressed with 'while'.
[...]
I agree. You don't understand. What confuses me is your complete lack
of interest in trying to understand.
Many of us are happy using C's for loop because we don't consider
it to be crippled. It is not a PITA to use it for the majority of
iterating loops; we just use a very common coding pattern like
for (int i = 0; i < N; i ++) {
// ...
}
We can write "i --" if we want the loop to run in reverse, or "i += 3"
if that's what we want.
Mistakes are possible, but rare. Mistakes are more likely in code
fragments in Usenet articles than in real-world code.
Sure, I could use a while loop rather than, say :
for (node *ptr = head; node != NULL; node = node=>next) {
// ...
}
but thanks to C's flexible for loop, I don't have to. And no,
I don't consider this loop "whacky".
We know that you *don't like* any of this, and that's fine, but
you cannot reasonably disagree with the observed fact that many C
programmers are able to use C-style for loops effectively.
If a future edition of the C standard added a for loop of the kind
you prefer, Id be fine with that, and I'd probably use it. Perhaps,
off the top of my head something like
for ((int i; first; last [; increment])) {
// ...
}
or
for (int i in first ... last [step increment]) {
// ..
}
But that's not likely to happen, because (a) as far as I know nobody
has proposed it, and (b) **it's not needed**.
You act as if you think we're all either lying or stupid for not
agreeing with your personal preferences. We're not.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */