Rust bandwagon
Rust bandwagon
Posted Jan 3, 2023 20:26 UTC (Tue) by Wol (subscriber, #4433)In reply to: Rust bandwagon by fenncruz
Parent article: Welcome to 2023
FORTRAN *would* execute the body of the loop. Once.
Fortran, as you say, wouldn't.
(Unless you use compiler specific extensions - the F77 compiler I used had a switch to enable the old FTN behaviour.)
I'm old enough to remember the difference between FORTRAN and Fortran :-) I've never heard of fortran.
Cheers,
Wol
Posted Jan 3, 2023 20:46 UTC (Tue)
by Wol (subscriber, #4433)
[Link] (2 responses)
DO I=10,1 would probably do an implicit STEP -1
J=10
Cheers,
Posted Jan 7, 2023 9:31 UTC (Sat)
by joib (subscriber, #8541)
[Link] (1 responses)
DO I=m1, m2
then m1 must be <= m2. So the loop in your example is invalid. You're most likely describing some compiler-specific extension (or accidental behavior later documented by the compiler developers as expected behavior. :) ).
Posted Jan 7, 2023 17:25 UTC (Sat)
by Wol (subscriber, #4433)
[Link]
Fortran allows a lot of (specified) behaviour in the name of optimisation, that can lead to unexpected results. Like storing the index of a do loop in a register, such that it can only safely be read, and not relied on when the loop exits. It seems highly likely that most FORTRAN compilers (and certainly the one I was using in 1983, iirc) did not bother to check the loop limits. Given that I understood that FORTRAN explicitly said the index,limit check was done at the *end* of the loop, I would be surprised if there was a special check on entering the loop.
When Fortran moved the check to the start of the loop, then it makes sense that loops can execute zero times.
Cheers,
Rust bandwagon
K=1
DO I=K,J would not execute in Fortran, but would execute once with I set to 10 in FORTRAN.
Wol
Rust bandwagon
Rust bandwagon
Wol