Sujet : Re: Checking the loop variable after the loop has ended (Was: Loops (was Re: do { quit; } else { }))
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.cDate : 18. Apr 2025, 14:58:08
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vttlpg$1treo$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vtrvc6$mjoi$1@dont-email.me>,
Lew Pitcher <
lew.pitcher@digitalfreehold.ca> wrote:
...
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;
Indeed. This is the common case - where you are looking for something, and
if you find it, you break out of the loop (one way or another). If you
don't find it, then the loop terminates "normally" - and you need to catch
that case.
for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;
if (n != -1) printf("Found key at entry %d\n",n);
Bart won't like the way you've abused C's "for" statement syntax to your
own devious ends...
(But I like it)
-- The randomly chosen signature file that would have appeared here is more than 4lines long. As such, it violates one or more Usenet RFCs. In order to remainin compliance with said RFCs, the actual sig can be found at the following URL: http://user.xmission.com/~gazelle/Sigs/Seneca