Sujet : Re: Loops (was Re: do { quit; } else { })
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 16. Apr 2025, 03:37:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtn55a$17107$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Mozilla Thunderbird
On 2025-04-15, bart <
bc@freeuk.com> wrote:
Note that C's for-loop is dumb; it merely take three expressions A B C
that can be completely unrelated, and arranges them into a loop:
>
A; while (B) {...; C}
Note that this problem is not unique to the for() statement. An
assignment statement allows you to arrange three unrelated expressions
together like
A = B + C;
"Doctor, it hurts when I hit my head with a hammer!"
"Then stop doing that."
The key to using the for() statement is to make sure the three
expressions are related appropriately. Many different powerful and
useful ways of using a for() statement have been shown in this thread
that are not equivalent to for(int i=start; i<end; i += increment).
Individually, those uses aren't particularly common, but collectively
I've needed each of those uses often enough to be grateful that C has
such a flexible construct to do it with.