Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!abvax!iccgcc!schmidtg From: schmidtg@iccgcc.decnet.ab.com Newsgroups: comp.lang.fortran Subject: Re: Re: Is this kosher? Message-ID: <3785.27ddfb30@iccgcc.decnet.ab.com> Date: 13 Mar 91 15:13:04 GMT Lines: 89 In article <1991Mar6.154720.1162@sbcs.sunysb.edu>, mlubran@csws5.ic.sunysb.edu (Michael J Lubrano) writes: >>In article <2787@dftsrv.gsfc.nasa.gov> jim@jagubox.gsfc.nasa.gov (Jim Jagielski) writes: >>>[ommitted stuff] >>> . >>> if (value .lt. 0) then >>> . >>> else >>>22 do something >>> . >>> end if >>> . >>> if (a.lt.b) goto 22 >>> >>>Is the above legal and acceptable... I can't find any references to it in my >>>books... >> > > A much better way to write this would be: > > 10 IF (VAL.LT.0)THEN > . > ELSE > C DO SOMETHING > . > END IF > . > C FORCE PROGRAM FLOW > IF(A.LT.B)THEN > VAL=100 > GO TO 10 > END IF > > setting VAL greater than 0 forces the conditional (VAL.LT.0) > to defualt to the else, which is exactly where you want to be. > > Q.E.D > > > Mike Lubrano Hmmm... looks like an infinite loop to me unless "do something" has an additional side effect of forcing (a .ge. b)!!! In general, you don't want to change control flow in your program by forcing variables to assume bogus values. Too many side effects, and what if you want to reuse that variable later on? Here is how I would approach the problem. . if (value .lt. 0) then . limit = 0 else limit = 1 end if if (a .lt. b) limit = limit + 1 end if do 22 i = 1,limit do something 22 continue -or- better still... . if (value .lt. 0) then . else call do_something() . end if . if (a .lt. b) then call do_something() end if -- ============================================================================= Greg Schmidt -> schmidtg@iccgcc.decnet.ab.com ============================================================================= "People with nothing to hide have nothing to fear from O.B.I.T" -- Peter Lomax ----------------------------------------------------------------------------- Disclaimer: No warranty is expressed or implied. Void where prohibited. =============================================================================