Sujet : Re: Loops (was Re: do { quit; } else { })
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 21. Apr 2025, 04:16:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250420200823.908@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-04-20, bart <
bc@freeuk.com> wrote:
But the thing is, once you split it into multiple lines, then there is
little advantage over using a regular 'while' loop:
The advantage may be little, but there is some.
p = sqliteHashFirst(&pSchema->trigHash);
while (p != NULL)
{
sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
p = sqliteHashNext(p) )
}
- In a while loop, if you "continue", it will jump to the top of
the loop, without executing the step.
- The loop controls are not gathered in one place.
- Because they are not gathered in one place, not only is it less
readable, but we cannot use while write a macro such as:
for_sqlite_hash (p, &pSchema->trigHash) {
if (some_condition_over(p))
continue; // doesn't stupidly repeat for the same p!
}
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca