Sujet : Re: Loops (was Re: do { quit; } else { })
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 16. Apr 2025, 12:32:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vto4fu$23kmr$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
User-Agent : Mozilla Thunderbird
On 16/04/2025 06:35, Janis Papanagnou wrote:
On 15.04.2025 22:46, bart wrote:
On 15/04/2025 20:07, Scott Lurndal wrote:
[...]
Real for loops _are_ a three-way construct.
>
[...]
>
Any step other than 1 is unusual. [...]
Nonsense. Arithmetic loop steps other than one are noting unusual
and been supported by programming languages (and also been used)
since decades in programming.
So what are you claiming, that the majority of loops in any given program will have steps other than +1 or -1?
THAT would be nonsense! For your benefit, I've done a survey of a 30Kloc C program (not one of mine). It has 181 for-loop statements, of which:
15 are endless loops (for (;;))
23 are either linked traversal or do something weird
143 seems to be simple integer interations
Of those 143, 137 count upwards with a step of +1; 6 count downwards with a step of -1.
So here, 0% of such loops have a step other than 1. THAT's what I mean by 'unusual'.
Scot Lurndal gave examples comparing C with BASIC/FORTRAN that used steps other than one, to back up a claim that they routinely use 3 components. Actually they rarely do.
There is something else: all 181 of those loops used the 'for' keyword. Which meant I had to painstakingly analyse them one by one to determine what they were (and probably overlooked some but the figures will be close enough).
Written in my language, 15 would be 'do' loops; 23 would likely be 'while' loops; and only those 143 would be 'for' loops.
No analysis necessary.
But never, mind, C's for-loop will still be the most superior to everybody here. I'd have an easier time arguing about religion!