Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Tue, 03 Feb 2026 03:47:30 -0800 Organization: A noiseless patient Spider Lines: 25 Message-ID: <86ldhajbfx.fsf@linuxsc.com> References: <20250413072027.219@kylheku.com> <20250415053852.166@kylheku.com> <20250415201754.605@kylheku.com> <87h62o2296.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 03 Feb 2026 11:47:38 +0000 (UTC) Injection-Info: dont-email.me; posting-host="72e789f1a61a439ff5daaffc25398413"; logging-data="1520319"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hwjyJx1nf72/pxmttt4nfWV9Tk4aZtGE=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Ytl86hMr5dRdNbMzgihaJRk63UE= sha1:znc37ocJ0iFoMjKX275pdUcTeo0= Xref: csiph.com comp.lang.c:396565 Keith Thompson writes: [...] > I could write a macro like: > > #define ITERATE(var, from, to) for ((var) = (from); (var) < (to); (var)++) > > but then anyone reading the code has to understand both how C-style > for loops work and how the ITERATE macro works. Does the expansion > use < or <=? What happens if "to" is INT_MAX? Did the author of > the macro get everything right? An advantage of using a macro is that these questions need be answered only once, rather than at every place a for() loop would appear. > Now if someone else finds that such a macro makes things easier for > them, that's fine. But often, *in my opinion*, such macros make code > harder to read for someone who knows C well. Whether using a macro like ITERATE() makes code harder to read or easier to read is a testable proposition, and as such it deserves to be treated as a question of fact rather than as a matter of opinion.