Sujet : Re: Loops (was Re: do { quit; } else { })
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 16. Apr 2025, 21:18:29
Autres entêtes
Organisation : None to speak of
Message-ID : <874iyn273e.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Gnus/5.13 (Gnus v5.13)
scott@slp53.sl.home (Scott Lurndal) writes:
bart <bc@freeuk.com> writes:
On 16/04/2025 15:09, Scott Lurndal wrote:
[...]
for(i = 1; i++ <= 10;)
>
So real for loops are a /two-way/ construct?
>
In any case, that doesn't do the same as the others, as it iterates over
2 to 11 inclusive, not 1 to 10.
>
The point was to execute a loop 10 times, which this does.
You didn't say that was the point. A very common requirement is to have
a meaningful value for i inside the loop. `for (i = 1; i <= 10;i ++)`
does that, and is far more idiomatic.
Your example does demonstrate the flexibility of a C-style for loop,
but it's not good code.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */