Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Sun, 11 May 2025 17:30:14 -0700 Organization: A noiseless patient Spider Lines: 64 Message-ID: <86h61qzn55.fsf@linuxsc.com> References: <87a58mqt2o.fsf@nosuchdomain.example.com> <20250413072027.219@kylheku.com> <20250415153419.00004cf7@yahoo.com> <86h62078i8.fsf@linuxsc.com> <20250504180833.00000906@yahoo.com> <86plggzilx.fsf@linuxsc.com> <20250511010917.00007702@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 12 May 2025 02:30:18 +0200 (CEST) Injection-Info: dont-email.me; posting-host="74b4e5895be58ca73eb02e8f9ff401e1"; logging-data="765375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HDs0zkmtk/CuTVL+UN0nOlRs4HP+MSqI=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:OniudTWYtBKLdjQl6G+Nv28mwEs= sha1:PLEeQCd7laNC4Rvh6vewVHkXXF0= Michael S writes: > On Sat, 10 May 2025 06:43:38 -0700 > Tim Rentsch wrote: > >> Michael S writes: >> >>> On Sun, 04 May 2025 07:31:11 -0700 >>> Tim Rentsch wrote: >>> [...] >>> Also having just one form of loop with pre-condition strikes me as >>> more elegant. Since elegance is strongly subjective, I have no >>> logical arguments in support of me feelings. >> >> In a recent posting I gave some statistics about the three different >> kinds of looping controls (while,for,do/while). do/while loops were >> almost 20% of all loops, and more than a quarter of the two kinds of >> loops other than for(). Besides being a more pragmatic choice, I >> think having the three kinds of loops be distinct in the language is >> a better choice, because how we think of the different kinds of loop >> is different, and it's helpful to have those differences be readily >> apparent in the program, rather than needing to reconstruct them by >> looking at code around the loop control fragment. > > That sounds like misunderstanding. > I didn't suggest one loop construct. I suggested two constructs: for() > for loops with pre-condition and do-while for loops with post-condition. Yes, I did misunderstand you. The alternative meaning didn't occur to me. I see it now. The same posting I mentioned in the previous response gave while() loops as occurring more than for() and do/while() combined. I conceptualize for() loops quite differently than while() loops, and vice versa. By analogy to the only-two-kinds-of-loops suggestion, the language could forego switch() and provide only if()/else. To me, neither of those what-might-be-called-simplifications seems like a good trade. Have you asked other people to see what their reactions are? Incidentally, a language change to C was once proposed, so that a do/while could also have an expression after the while(). Note that this change is backwards compatible with C as it is, because a simple semicolon after while() is an empty statement. Adopting this proposal would mean that the language would allow, for example do { // this part will always be done at least once // and once more for each time 'condition' is true } while( condition ){ // this part will be done zero or more times } allowing a convenient way of writing "loop-and-a-half" type loops. Do you have any reaction to this idea? Suppose the just plain while() style were eliminated, so ordinary while() loops would instead be written as do ; while( condition ){ // body of while loop } Is that better or worse than having a separate while() statement?