Sujet : Re: Loops (was Re: do { quit; } else { })
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 21. Apr 2025, 22:21:30
Autres entêtes
Organisation : None to speak of
Message-ID : <87o6wp1a91.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
[...]
I don't now think think there is any argument that will make any
difference. People here genuinely think that writing:
>
for (ch = 0; ch <= 255; ++ch)
>
is far superior to this 'primitive' version:
>
do ch = 0, 255
>
No amount of discussion or arguments will make them change their minds.
You misunderstand.
The idea that the C-style loop is "far superior" is your invention.
Your attempts to summarize the opinions of people you so strongly
disagree with have largely been unsuccessful. Perhaps my attempts
to summarize your opinions would also be unsuccessful, though I
*think* I understand your opinions better than you understand mine.
If I'm programming in C, the C-style for loop is better because it
exists and doesn't fail with a syntax error.
If I'm programming in a language (Fortran?) that provides the second
form but not the first, the second form is obviously better for
exactly the same reason.
I think that really is 90+% of what programmers think about when
choosing how to write a loop: What does the language provide?
Most programmers would consider complaining more that briefly
that they dislike a given construct to be a waste of time. Sure,
griping about programming languages is common, but less common that
just getting on with the job of using the language.
Yes, the Fortran style loop is shorter than the C-style loop.
Few programmers care as much as you do how many characters or tokens
are needed for a given construct.
[...]
Apparently, the C form is superior because that construct can also be
used to conveniently express link-list traversal, and a lot more.
I don't know that I'd use the word "superior", but it's certainly an
advantage.
Even the idea of having *two* kinds of loop, one as it works now, and
one more streamlined, was not acceptable: too much 'overloading' of
the language.
Like any idea, some people would like it, some would accept it,
and some would dislike it. It is certainly the case that the kind
of for loop you'd prefer is not *necessary* in C, since everything
it can do can be done using the existing C-style for loop (perhaps
with some trickery to avoid overflow at the upper or lower bound).
Do not infer from that that I think a language should only provide
"necessary" features.
C-style for loops have been used successfully for decades, and have
been adopted by other languages (including bash, which isn't
particularly C-like).
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */