Sujet : Re: Loops (was Re: do { quit; } else { })
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 21. Apr 2025, 12:34:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vu5afk$23f8f$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
bart <
bc@freeuk.com> wrote:
On 19/04/2025 20:22, James Kuyper wrote:
...
I wasn't talking about him finding the tools problematic. I was talking
aobut him find it difficult to ensure that the expressions are not
arbitrary unrelated expressions, but are in fact correctly related
expressions. If you cannot ensure that A, B, and C have the correct
relationship to make for(A; B; C) work as needed, then you also lack to
ability to make sure that the expressions in {A; B; C:} work together as
needed, and that ability is fundamental to computer programming.
In other words, the feature is dumb.
The feature allows you to pack all of the loop management stuff together
where it's easy to check and think about. It can be misused, by putting
together stuff that has nothing to do with loop management, just as an
assignment statement can be misused by writing, for instance
annual_salary = current_income + age;
The compiler cannot do any checking: for (i=0; i<n; ++n) is fine.
The compiler cannot tell you what's wrong with that assignment
statement, either.
Even in BASIC, if I do this:
for i=1 to n
next n>
it will say that n does not match. And here it is optional; in C that
part is necessary.
It's been a while since I've written basic, but looking at that syntax I
believe it would be equally feasible to write
for i=start_year to months_per_year
Can BASIC protect you from misusing it's for statement by putting in the
wrong expressions for the start and end of the loop? Then why would
expect C's loop construct to do any better?
But, you have a bizarre take on this: if somebody calls it out, then
rather than agree with them, you will personally insult the person who
said it, and suggest that if they are incapable of such a simple check,
then they shouldn't be coding.
How can I respond by agreeing with an incorrect assessment? And the
insults are the consequence of your endlessly successful search to find
new ways to misunderstand C.
The fact is that people make typos (obviously, not you or JP or SL or
I make typos all the time. I love language features that let me catch my
typos. That's one reason why I like languages that provide features like
"for each employee in employee_list", but I see little advantage to a
for statement limited in the fashion you desire. It's easily emulated by
the more flexible for-statement that also allows me to do many other
things as well.