| Deutsch English Français Italiano |
|
<871ptu4dus.fsf@nosuchdomain.example.com> 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: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Loops (was Re: do { quit; } else { })
Date: Mon, 14 Apr 2025 14:44:59 -0700
Organization: None to speak of
Lines: 61
Message-ID: <871ptu4dus.fsf@nosuchdomain.example.com>
References: <vspbjh$8dvd$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>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 14 Apr 2025 23:45:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="81eb20b1af8ee11d07b9431bae23cc05";
logging-data="2296845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18j9sxqFPEODsE8bfPyEs5l"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:48NU1nLEHMEzl8HU8w3hZSFAHuM=
sha1:B8tavdMXIbCN9I3qpwTchp6BJGg=
Bytes: 3730
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> (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:
[...]
>> Fortran's loops looked like this:
>>
>> do 100 i = a, b
>> s1
>> s2
>> ...
>> 100 continue
>
> Okay, I see what you want; just two values (from, to).
>
> This Fortran stuff looks really sick (for my taste)! - The "do 100"
> sounds like iterating 100 times, line numbers, 'continue' keyword,
> and a list a,b meaning iteration over a range. - Can it be worse?
> (Later Fortran versions allow a slightly better syntax, but it's
> basically the same anachronistic crude syntax.)
To any programmer familiar with that version of Fortran, the 100 doesn't
look like iterating 100 times. It looks like a label, and it's
reasonably consistent with other constructs that refer to labels. The
syntax isn't great, but don't judge an unfamiliar language syntax by one
example.
> In _minimalistic_ languages I'd prefer, for example, a style like
> in Pascal (or in similar languages)
>
> for i := a to b do
> statement_block;
>
> It's simple, and a clean formalism.
>
>>
>> The C equivalant is this:
>>
>> for (i = a; i <= b; ++i)
>> stmt
>>
>> Differences:
>>
>> * Fortran has an official loop index variable 'i'.
>
> You are saying that you could not use 'j' ? (This is certainly
> different from my memories.) - Anyway, having dedicated variables
> for integer types is sick in itself, also if used without loop.
No, he's saying that in the example Fortran loop "do 100 i = a, b", the
variable i is the index variable for that loop. It could be any
variable name. (Fortran defaults variables with names starting with
i..n to integer; "implicit none" overrides that and requires everything
to be declared. I'm not certain whether modern Fortran still does that.)
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */