Liste des Groupes | Revenir à cl c |
On Thu, 17 Apr 2025 21:21:54 +0000, Kenny McCormack wrote:
>In article <87fri68w2c.fsf@nosuchdomain.example.com>,>
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
...IMHO it doesn't much matter what the value is after the loop ends, but
any standard for a language with such a feature should either restrict
the scope to the loop, specify the value the variable has after the
loop, or explicitly say that it's unspecified or undefined.
I frequently check the value of the loop variable after the loop has ended
in order to determine if the loop ended "normally" or prematurely via
"break". E.g.,
for (i=0; i<10; i++) { code that might or might not break }
if (i == 10) puts("It ended normally");
It's also a handy idiom for a compact list search loop
where the terminating condition is either end of the list, or
a matched entry.
If the cursor isn't the end-of-list marker, then it references
the matched entry;
>
for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;
Les messages affichés proviennent d'usenet.