Sujet : Re: Loops (was Re: do { quit; } else { })
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 22. Apr 2025, 20:43:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vu8rhf$18fhc$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla Thunderbird
On 22/04/2025 20:11, David Brown wrote:
On 22/04/2025 20:54, bart wrote:
Well C's would be:
>
For (first ingredient; ingredient; next ingredient)
The point was that you claimed your loop matches how you would describe things in English.
And it does exactly that. I get why people decide to go up several levels to try score some points, but we're not talking about AI here where we are trying to extract the exact algorithm that might have been in the mind of the programmer.
This:
a=b;
while (c) {
d;
e;
}
can alway be directly translated to English, a line at a time:
Assign b to a; While c: (Do d, Do e)
The only liberty taken is turning ") {}" into ": ()".
Now try that with the equivalent "for (a=b; c; e;) {d;}. There is no direct mapping.
But if you want do it your way, what algorithm ss being expressed here:
for(a; b; c) {d}
You can't do it; there isn't enough information, or you'd have to analyse it more deeply. However you CAN describe the outline of what is being executed, and you CAN port that to a different language, just about.
Here it is in Python (it may need the details tweaked):
a
while b:
d
c
And guess what - it's a WHILE loop!
Whichever way you want to slice it, FOR(A;B;C) is a glorified WHILE loop. And a lot of the time it is much better suited as such.