Sujet : Re: Loops (was Re: do { quit; } else { })
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 20. Apr 2025, 23:07:20
Autres entêtes
Organisation : None to speak of
Message-ID : <87ldruv65j.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
[...]
Actually here's a example from sqlite3.c:
>
for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
}
>
And this is how you might be forced to write it instead:
>
p=sqliteHashFirst(&pSchema->trigHash);
while (p) {
sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
p=sqliteHashNext(p);
}
>
Yes, it's spread over two more lines, but so what? It's much clearer:
the initialisation is done once and then it's out of the way. Setting
p to the next value is now physically written after the body.
[...]
I understand and completely accept that you find the while loop
clearer, and I have no interest in changing your mind.
I find the for loop clearer. I won't speak for anyone else, but I
suspect a lot of C programmers would also find the for loop clearer.
I don't believe you've ever acknowledged that.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */