Deutsch English Français Italiano |
<vtlcg0$3f46a$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Tue, 15 Apr 2025 11:30:24 +0100 Organization: A noiseless patient Spider Lines: 106 Message-ID: <vtlcg0$3f46a$2@dont-email.me> References: <vspbjh$8dvd$1@dont-email.me> <vt5js2$g1t7$1@dont-email.me> <20250409142303.00004645@yahoo.com> <87ikndqabc.fsf@nosuchdomain.example.com> <20250410115501.000037a5@yahoo.com> <vt8ei8$2vn84$1@dont-email.me> <20250410080629.532@kylheku.com> <vt94q5$3jjod$1@dont-email.me> <vt9628$3hhr8$3@dont-email.me> <vtammh$174ev$1@dont-email.me> <vtavn9$1dp7m$3@dont-email.me> <vtb8nv$1plb2$2@dont-email.me> <vtba81$1qfbm$1@dont-email.me> <vtbc6o$1te2o$1@dont-email.me> <vtbhjv$24api$1@dont-email.me> <vtbn2k$293r1$1@dont-email.me> <vtc19j$2kqlj$1@dont-email.me> <87a58mqt2o.fsf@nosuchdomain.example.com> <vtc7mp$2q5hr$1@dont-email.me> <vtcqf6$3j95s$1@dont-email.me> <vtdh4q$b3kt$1@dont-email.me> <vtf7fe$1qtpg$1@dont-email.me> <vtgfuf$31ug1$1@dont-email.me> <20250413072027.219@kylheku.com> <vtgpce$39229$1@dont-email.me> <vti2ki$g23v$1@dont-email.me> <vtin99$vu24$1@dont-email.me> <vtiuf0$18au8$1@dont-email.me> <vtj97r$1i3v3$1@dont-email.me> <vtl166$36p6b$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 15 Apr 2025 12:30:24 +0200 (CEST) Injection-Info: dont-email.me; posting-host="cec4580467d8bef69918f71b92c931ef"; logging-data="3641546"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6M62cJmo7SNkuvS+H/cay" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:sQVnTBRdu3VeB0FG16R+9PWF984= Content-Language: en-GB In-Reply-To: <vtl166$36p6b$1@dont-email.me> Bytes: 5522 On 15/04/2025 08:17, Janis Papanagnou wrote: > On 14.04.2025 17:22, bart wrote: >> On 14/04/2025 13:18, Janis Papanagnou wrote: >>> (While there's some "C" stuff in here it contains a lot of non-"C" >>> samples for comparison. So [OT]-sensible folks may want to skip this >>> post.) >> >>> [...] >> >> I'm not saying there's anything wrong with it. The point was that an A >> to B loop existed in the 1950s; C came out in the 1970s! >> >>> [...] >> [...] >> >>> which of course would be written with a 'while' >>> >>> int i = a; >>> while (i <= b) f(i++) >> >> That would be a poor use of 'while'. > > Not the least. > >> And bizarre, to use 'while' for >> iteration, but 'for' for loops that are best written as while! > > I was merely trying to provide some options to address your dislike. > >> >>> The "C" syntax has actually a flexibility that is very valuable. >> >> The flexibility is the problem, because you have to specify the loop in >> such excruciating detail. It is easy to make a mistake which results in >> still legal code. And you now have to analyse each loop to see what kind >> of loop it is: > > Well, our opinions obviously differ. I just give you two examples > (and there's many variants of these) of not uncommon 'for' usages... > > for (c=0; bitstr; c++) > bitstr &= bitstr-1; I can't grok that. > for (r=1; r<=0x80; r<<=1) > ... > and someone already posted another iteration type on linked lists > > for (node = list; node; node = node->next) These two I get, and I can tell you that they're all WHILE loops. To make make them tidier, I'd have fewer complaints about them if they instead looked like this: while (node = list; node; node = node->next) So, you can optionally add extra elements to a while (x). It would be necessary to either define whether while(x; y) means while (; x; y) or while (x; y), or to always require either zero or two semicolons inside (...). That could have kept 'for' for how it works in other languages (the ones that haven't just blindly copied C's version!). > The point here is the observation that there are loops that deviate > from simple counted loops (and that are commonly used) and that they > all comprise the same principal structure; initialization, condition > test, change of loop-variables. The "C" loop syntax reflects that in > its typical low-level syntax form. (I already said that personally I > don't like "C"'s syntax, but I do like its flexibility.) Let me ask you this: what exactly is the point of the 'while' statement in C? Since it can always be trivially be written as: for (;cond;) It seems to that most use cases (initialise, check exit condition, change something that affects the letter), would suit 'for' better. But since 'for' then becomes overloaded, there ought to be a dedicated feature for simple iteration. So it seems the solution is as a I suggested above. >> [...] >> >> Suppose you see 'i <= N' as the condition; is that '<=' intentional, or >> is it a typo for '<'? It's impossible to tell. > > (This is nonsense.) You can't just say that without explanation. WHY it it nonsense? Take this: for (i=0 i<=N; ++i) Most such loops iterate over 0..N-1 inclusive, so would need "<". So, in your opinion, is that <= a typo, or is the intention to iterate over 0..N inclusive (so N+1 iterations)? (May reply to rest separately.)