Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Fri, 18 Apr 2025 18:27:44 +0100 Organization: A noiseless patient Spider Lines: 51 Message-ID: References: <20250415053852.166@kylheku.com> <878qnz27sj.fsf@nosuchdomain.example.com> <87r01rzl89.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 18 Apr 2025 19:27:45 +0200 (CEST) Injection-Info: dont-email.me; posting-host="225decbae7f6d1b66db568edbb209aee"; logging-data="3640483"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YE0IFKMbMV7VkcqlyZ8VY" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:XCVK+oFqFhend5Qt46TQa3gqWLw= Content-Language: en-GB In-Reply-To: Bytes: 3318 On 18/04/2025 17:58, Scott Lurndal wrote: > bart writes: >> On 18/04/2025 14:37, Janis Papanagnou wrote: > >> >> * Scott Lurndal (SL) makes a claim that all 'real' for-loops have 3 >> parts, like C's for(A; B; C) [point 1] > > Again you mischaracterize what was stated. I simply > pointed out that most major programming languages have three component > looping constructs using the 'for' keyword, including C. Apart from C, simple iteration via a loop index has 4 things that need to be denoted: - Some keyword to say this is such a loop - The loop index variable - The start value - The end value Many can have an /optional/ step (or means to reverse the order) in the odd cases where that is necessary, making 4/5 if you want to be formal. C is quite different; it is merely 3 arbitrary expressions, the middle one of which is used as a loop terminating condition (tested notionally at the start of the loop). But in cases where it is used to emulate the kind of loop described above, then the same applies, except that: - It will always be 5 parts (the step always has to be accounted for) - Nearly everthing about how it works has to be imparted to the compiler: - The actual expression to initialise the variable - The exact expression used for the terminating condition - The exact expression used for incrementing to loop index - The end value that appears in the terminating condition is frequently offset (also can also be the case in real for-loops used in 0-based languages) - A loop which counts down may well have a quite different pattern from an upward counting one So a comparison between C for-loops and more formal ones is not that meaningful.