Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson 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: <87a58mqt2o.fsf@nosuchdomain.example.com> <20250413072027.219@kylheku.com> 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 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 */