Sujet : Re: Loops (was Re: do { quit; } else { })
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 16. Apr 2025, 12:01:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vto2mb$20c4n$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
User-Agent : Mozilla Thunderbird
On 16/04/2025 06:19, Janis Papanagnou wrote:
On 15.04.2025 12:30, bart wrote:
(One of your fundamental problems with "C" seems to be to understand
the 'for' keyword meaning only counted loops with one variable and a
simple +1 increment. - I can't help you here.)
And your problem seems to the opposite: being unable to understand that for-loop (perhaps spelled 'do') can be a specialised feature to iterate one or more variables over a predetermined range or set of values.
Unlike C's for, which is just a gimmick where you bundle three potentially unrelated expressions and hope for the best.
Everyone here is defending the latter to the death. Why? Apparently the ONLY argument is 'flexibility'.
Having to writing a simple iteration in such a convoluted and unchecked manner is much better because - you can use the same syntax to iterate over a list!
I've written code where the logic required comparisons of i < N-1
and also i <= N . So what? - Should I not do that because you are
getting confused when inspecting my code?
This is worrying. So you have a bunch of code with multiple like this:
for (i=0; i<N; ++)
for (i=0; i<N; ++)
for (i=0; i<=N; ++)
for (i=0; i<N; ++)
And you notice one has <= while the others have <. But according to you, this is nothing remarkable and raises no flags. Obviously the author intended to iterate one more time there!
With language-supported iteration, the comparison operator is not exposed, so the programmer cannot accidentally type the wrong one.
(I see I have ++ and not ++i; never mind. It is telling that it took me a minute to notice!)