Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Michael S Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Wed, 7 May 2025 12:32:32 +0300 Organization: A noiseless patient Spider Lines: 41 Message-ID: <20250507123232.00005f8b@yahoo.com> References: <20250413072027.219@kylheku.com> <20250415053852.166@kylheku.com> <20250416173721.000030b5@yahoo.com> <86ecx13nfb.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Wed, 07 May 2025 11:32:32 +0200 (CEST) Injection-Info: dont-email.me; posting-host="03e79b8836900277a86ec1f1686716bd"; logging-data="968528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VprIj0azIVXz2rQ5b8IyayJX56A7cA/0=" Cancel-Lock: sha1:ouPzeKVw/kN57Xjpd76QpBg/ry0= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) On Tue, 06 May 2025 05:59:20 -0700 Tim Rentsch wrote: > Michael S writes: > > > On Wed, 16 Apr 2025 14:09:44 GMT > > scott@slp53.sl.home (Scott Lurndal) wrote: > > > >> bart writes: > >> > >>> On 15/04/2025 20:07, Scott Lurndal wrote: > >>> > >>>> > >>> Let's look at that C again: > >>> > >>> for (int i = 1; i < 11; i += 1) # 15 tokens; C > >> > >> for(i = 1; i++ <= 10;) > > > > I'd reject this code during review. > > Hopefully, you too. > > I'm curious to know the basis for your reaction. What about the > code would prompt your judgment to reject it? Is it just a > specific reaction, or does it represent some more general pattern > (and if so then what more general pattern)? First and foremost it was tongue-in-cheek reaction to the article that Scott posted 2-3 minutes after the article that I was reacting to. At the next level, it is true that if I do detailed code review (which I almost never do) I would indeed reject this code. The first and sufficient reason is that the code looks superficially similar to very common idiom, but significantly differs in behavior. An additional reason is that post-increment operator is generally harder to reason about than almost any other C operator, esp. so when used as part of comparison, so, IMHO, readable code should limit use of post-increment to very common idioms (or altogether avoid it). The third reason, related to the first two is that behavior of this loop is way too surprising.