Path: utzoo!attcan!uunet!mcvax!ukc!harrier.ukc.ac.uk!eagle.ukc.ac.uk!trh From: trh@ukc.ac.uk (T.R.Hopkins) Newsgroups: comp.lang.fortran Subject: Re: Dubious Fortran Construct Keywords: Standard Fortran 77 Message-ID: <6172@eagle.ukc.ac.uk> Date: 13 Dec 88 17:41:52 GMT Organization: Computing Lab, University of Kent at Canterbury, UK. Lines: 56 +From eagle.ukc.ac.uk!harrier.ukc.ac.uk!ukc!mcvax!uunet!husc6!mailrus!purdue!i.cc.purdue.edu!h.cc.purdue.edu!s.cc.purdue.edu!ags Tue Dec 13 17:29:53 GMT 1988 + +In article <22994@sgi.SGI.COM+ bron@bronze.SGI.COM (Bron Campbell Nelson) writes: + [asks whether this is legal] ++ ++ subroutine foo(a, b, n) ++ real a(n), b(n,n) ++ do 10 i = 1,n ++ if (a(i) .eq. 0) goto 10 ++ do 10 j = 1,n ++ b(i,j) = 1/a(i) ++10 continue ++ ++ return ++ end + +This is illegal according to the ANSI standard. The range of a DO loop, by +definition, consists of all the executable statements following the DO, up +to and including the loop termination statement. Therefore the CONTINUE is +part of the range of the inner DO. (It also happens to be part of the +range of the outer DO, but that's irrelevant). + +The GOTO is outside the range of the inner DO, but its destination is +inside the range. Therefore, it's illegal. + +-- +Dave Seaman +ags@j.cc.purdue.edu + + ANSI X3.9-1978 page 11-6 line 34 (in the section Range of a DO-loop) says "More than one DO-loop may have the same terminal statement" Section 11.10.2 states A DO-loop is either active or inactive. Initially inactive, a DO-loop becomes active only when its DO statement is executed. Seems to me that when the GOTO is executed the inner loop is inactive. The effect of the transfer is thus to increment the outer loop counter (see 11.10.3 and 11.10.4) and restart the outer iteration. The code is thus legal Fortran 77. Tim -- Tim Hopkins, { trh@ukc.ac.uk Computing Laboratory, trh%ukc@cs.ucl.ac.uk University of Kent, na.hopkins@score.stanford.edu } Canterbury CT2 7NF, Kent, UK.