Official Fortran standards
Toon Moene
toon@moene.indiv.nluug.nl
Sat Jun 22 14:43:00 GMT 2002
Robert Dewar wrote:
> > Well, the Fortran77 standard states:
> > When a DO-loop becomes inactive, the DO-varible of the DO-loop
> > retains its last defined value.
> >
> > So you get the current value if you jump out of the loop, or the next
> > value (one increment greater than last) if you fall thru.
> The last defined value could only mean the value the last time through the
> loop. It certainly cannot be one greater since the loop might have an upper
> bound equal to the highest allowed integer value.
Hmmm, I don't think this is correct.
Quoting http://www.fortran.com/F77-std/rjcnf-11.html#sh-11.10.7:
"Incrementation processing has the effect of the following steps
performed in sequence:
1.The DO-variable, the iteration count, and the incrementation
parameter of the active DO-loop whose DO statement was most
recently
executed, are selected for processing.
2.The value of the DO-variable is incremented by the value of the
incrementation parameter m3.
3.The iteration count is decremented by one.
4.Execution continues with loop control processing (11.10.4) of the
same DO-loop whose iteration count was decremented."
IOW, the DO-variable is incremented before the decision whther the loop
should be terminated is taking.
This is confirmed by the examples given in the Fortran 77 standard:
"For example:
N=0
DO 100 I=1,10
J=I
DO 100 K=1,5
L=K
100 N=N+1
101 CONTINUE
After execution of these statements and at the execution of the CONTINUE
statement, I=11, J=10, K=6, L=5, and N=50."
Note the value of I.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
More information about the Gcc
mailing list