Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: DO loops, anyone? Message-ID: <11020@lanl.gov> Date: 24 Mar 89 01:10:43 GMT References: <1917@devsys.oakhill.UUCP> Organization: Los Alamos National Laboratory Lines: 41 From article <1917@devsys.oakhill.UUCP>, by steve@oakhill.UUCP (steve): > [...] > Going back to my code: > > k = 0 > do 10 i = 1,10 > if (i.eq.1.or.i.eq.5) goto 10 > do 10 j = 1,10 > if (j.eq.3) goto 10 > 10 k = k + 1 > > I assume this puts you in the camp that when i = 1 or i = 5 that > k is not incremented. There is a large segment of coders that think > it should be. [...] Consider: do 10 i = 1,10 if (i.eq.1.or.i.eq.5) goto 10 do 10 j = 1,10 10 array(j)=array(j)+1 This is the same as your loop except for the final statement (your final IF statement is a no-op and should be eliminated by a smart compiler anyway). Here it is quite clear that the array incrementing should _NOT_ be done as a result of the outer loop GOTO - in the first pass the variable J hasn't even been defined yet! As I pointed out before, either the branch should be illegal or the semantics should be: k = 0 do 10a i = 1,10 if (i.eq.1.or.i.eq.5) goto 10a do 10 j = 1,10 if (j.eq.3) goto 10 10 k = k + 1 10a continue This interpretation is at least consistent and well defined on both examples. J. Giles Los Alamos