Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.fortran Subject: Re: Dubious Fortran Construct Keywords: DO loops; transfer of control Message-ID: <14994@mimsy.UUCP> Date: 14 Dec 88 08:26:11 GMT References: <22994@sgi.SGI.COM> <3672@s.cc.purdue.edu> <1740@devsys.oakhill.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 52 Summary of problem: DO 10 I=A,B IF (cond) GOTO 10 DO 10 J=C,D code 10 CONTINUE more code Background: the problem arises only because the scope of a DO loop is named by a label that may be shared. In other programming languages one escapes by, in essence, forcing programmers to write the inner loop using a different label. Often the label is omitted altogether: do i in [a..b] if cond then do j in [c..d] code od fi od Claim: There is a simple and consistent way to view this problem that makes the `goto' illegal. Approach: since `the range of a DO loop includes the final statement', one should view the code as having an invisible loop delimiter that appears just *after* the labelled statement. Thus the example transforms to: DO I=A,B IF (cond) GOTO 10 DO J=C,D code 10 CONTINUE end do J end do I more code That is, because the DO J loop used label 10 as its final statement, its end appears just *after* the continue statement. The `IF' therefore jumps into its loop. Note that this interpretation of DO-loops gives consistently correct compilations of all other legal constructs. It also seems to me `intuitively proper'. One cannot end the loop *before* the labelled statement (since it must be executed if it in fact does something), and it seems nonsensical to say that the loop ends somehow `inside' the labelled statement, therefore it must end just after---`between the lines', as it were. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris