Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Mon, 21 Apr 2025 03:16:06 -0000 (UTC) Organization: A noiseless patient Spider Lines: 30 Message-ID: <20250420200823.908@kylheku.com> References: <20250413072027.219@kylheku.com> <87ecxmv4t4.fsf@nosuchdomain.example.com> Injection-Date: Mon, 21 Apr 2025 05:16:06 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c13f5017c98192b6c07a0b629837b649"; logging-data="1393164"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18a6yrbLa/kF2CtFS0DK6tBzo36GBkj8zE=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:aWGIX/fwa0T6PG8jms6aE9UC7rQ= On 2025-04-20, bart 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/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca