Path: utzoo!utgpu!tmsoft!dptcdc!dpmizar!swrinde!cs.utexas.edu!oakhill!steve From: steve@oakhill.UUCP (steve) Newsgroups: comp.lang.fortran Subject: Re: Dubious Fortran Construct Summary: I think you are wrong. Keywords: DO loops; transfer of control Message-ID: <1734@devsys.oakhill.UUCP> Date: 9 Dec 88 15:39:14 GMT References: <22994@sgi.SGI.COM> <3672@s.cc.purdue.edu> Organization: Motorola Inc. Austin, Tx Lines: 56 In article <3672@s.cc.purdue.edu>, ags@s.cc.purdue.edu (Dave Seaman) writes: > 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. I am not sure, but I think you are wrong. I do not have my copy of my standard here, so I can not reference it, but I think the code is correct. I think the standard defines the CONTINUE to be in the range of the currently active loop (in the case in question - the outer) when it is the terminal line of multiple DO loops. I know that most compilers will accept this line (then again most compilers will allow as certain amount of jumping into DO loops). I know that the compiler I worked on handled this properly (As I define it :-) ), since I am the one who implemented the code which handles this. Also I use to work for a company that demanded rigid compliance to the FORTRAN standard (for portability), and this was an accepted practice in the style guide (so if it is not truely "STANDARD" code, it is a standard coding practice). I will look up this question at home this weekend, and will post back early next week if noone quotes chapter and verse from the standard (someone who has the standard nearby - please save me the trouble :-) ). enough from this mooncalf - Steven P.S. I am sorry for not replying to the original posting, but we lost several days of mail some days ago, and this posting was probably in it. Anyway I didn't see the post (and I read c.l.f daily). ---------------------------------------------------------------------------- These opinions aren't necessarily Motorola's or Remora's - but I'd like to think we share some common views. ---------------------------------------------------------------------------- Steven R Weintraub cs.utexas.edu!oakhill!devsys!steve Motorola Inc. Austin, Texas (512) 440-3023 (office) (512) 453-6953 (home) ----------------------------------------------------------------------------