Deutsch   English   Français   Italiano  
<vtll0g$3n29t$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!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 13:55:43 +0100
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <vtll0g$3n29t$1@dont-email.me>
References: <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> <ilprvj5jbpcbr7fts2kdotfb81763u652g@4ax.com>
 <vtlbja$3f46a$1@dont-email.me> <20250415152550.00007634@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 15 Apr 2025 14:55:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cec4580467d8bef69918f71b92c931ef";
	logging-data="3901757"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18YROfmiNgaVdWDil/ijqNj"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:QANlxzrc6AP4ENknvdaucy4vw0Q=
Content-Language: en-GB
In-Reply-To: <20250415152550.00007634@yahoo.com>
Bytes: 4937

On 15/04/2025 13:25, Michael S wrote:
> On Tue, 15 Apr 2025 11:15:06 +0100
> bart <bc@freeuk.com> wrote:
> 
>> On 15/04/2025 05:57, Rosario19 wrote:
>>> On Mon, 14 Apr 2025 14:18:39 +0200, 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.)
>>>>
>>>> On 14.04.2025 12:16, bart wrote:
>>>>> On 14/04/2025 05:23, Janis Papanagnou wrote:
>>>>>> On 13.04.2025 18:39, bart wrote:
>>>>>>> [...]
>>>>>>>
>>>>>>>      for(let i = 1; i <= 36; i++) {
>>>
>>> C for loop is great, but all can be workarounded with goto label
>>
>> For this specific example (ignore 'let' for C), please explain why it
>> is better than, say:
>>
>>       FOR(i,1,36) {
>>
>> This is 99% of my for-loops. Is it the same reasoning why I have to
>> write 'break' in 99% of my switch-blocks?
>>
>> There's something about this group which celebrates these annoying
>> language characteristics which are only useful or meaningful in a
>> tiny minority of cases: see how wonderful it is for 1% of the time?
>>
>> That must surely justify them being both a PITA and dangerously error
>> prone in the vast majority of cases!
> 
> I regularly use two languages with "proper loops" - Matlab/Octave and
> VHDL (Ada-like syntax). When writing loops in these languages, I don't
> feel any extra convenience over C.

I'm not familiar with those, but the first Ada loop example I googled 
for was this:

   for Variable in 0 .. 9 loop

In C that exact example would be:

   for (Variable = 0; Variable < 10; ++Variable) {

or maybe:

   for (Variable = 0; Variable <= 9; Variable = Variable + 1) {

So, in the Ada:

  * Not having to write the variable 3 times (with C not always being
    able to detect if they didn't match)

  * Not having to either offset the upper limit, or juggle between <
    and <=

  * Not having to explicitly provide the code to increment the variable

doesn't have ANY extra convenience?

(You can have a 100MB compiler and you still have to tell it how to 
increment a loop index! That is plain crazy.)

> And it's not because I can become accustomed to anything. E.g. I am
> using tcl for a long time. I never stopped hating most of its syntax,
> including for loops.

TCL's for loop appears to be inspired by C's:

   for {set Variable 0}  {$Variable < 10} {incr Variable} {

It's extraordinary how difficult a task it appears to be with some 
languages to iterate a variable over a range!

I acknowledge that with the popularity of zero-based languages, which 
means usually iterating over 0..N-1 inclusive rather than 1..N, there is 
some confusing about denoting the upper limit.

So I invented a new postfix operator which turns an inclusive upper 
limit into an exclusive one. It looks like "-1", and works like this:

   FOR Variable in 0..N-1

Most C code I write manually is small sequences mainly to do with 
compiler testing and benchmarks. 'for'-loops and especially 'printf' 
feature heavily.

Those are two features with an unnecessarily elaborate syntax where you 
have to dot all the i's and cross all the t's, even for temporary code 
that is only needed for a few minutes.

That is incredibly annoying, especially as I am a terrible typist.