Path: utzoo!mnetor!uunet!husc6!cmcl2!beta!unm-la!unmvax!nmtsun!hydrovax From: hydrovax@nmtsun.nmt.edu (M. Warner Losh) Newsgroups: comp.lang.fortran Subject: Re: Modifying iteration variables in DO loops Message-ID: <1328@nmtsun.nmt.edu> Date: 3 Feb 88 03:41:16 GMT References: <1309@nmtsun.nmt.edu> Organization: NMT Hydrology program Lines: 48 Keywords: X3 standard FORTRAN 77 Summary: WRONG or RTFM In article <1309@nmtsun.nmt.edu>, john@nmtsun.nmt.edu (John Shipman) writes: > In section 11.10 of X3.9-1978, the FORTRAN 77 standard (pp. 11-5 to > 11-9), there is no statement about prohibiting the modification of a > DO variable within a loop. The standard defines how this works for WRONG. 11.10.5 (pg 11-8) EXECUTION OF THE RANGE. Statements in the range of a DO-loop are executed until the terminal statement is reached. Except by the incrementation described in 11.10.7, the DO-variable of the DO-loop may be neither redefined nor become undefined during the execution of the range of the DO-loop. So, in other words, the redefinition of a loop variable is prohibited inside the range of a loop. You can't assign a value to a loop variable, that, according to the standard, is a redefinition of the loop variable. > > For example, with some mythical standard-conforming compiler, this loop > would be executed twice, and the final value of COUNT would be 5: > > do 86 count = 1, 2 > count = count + 1 > 86 continue > WRONG WRONG WRONG WRONG WRONG WRONG WRONG There is NO CORRECT answer here, since this isn't a standard following program. According to section 13.10.5 sighted above, the assignment to count is NOT ALLOWED IN A STANDARD CONFORMING PROGRAM. > I bet NOBODY has a standard-conforming compiler. WRONG. Since this is a not a F77 program, you can't feed it to a F77 compiler and say that the compiler is broken. As a side note : On VMS, the FORTRAN compile gives a warning message telling me that I was modifying a loop variable. One final thing, when you quote some text, please make sure that you have read the supporting text around it before using the quotation out of context. -- bitnet: losh@nmt.csnet M. Warner Losh warner@hydrovax.nmt.csnet ! Don't know if this works, let me know. csnet: warner@hydrovax.nmt.edu uucp: ...{cmcl2, ihnp4}!lanl!unmvax!nmtsun!warner%hydrovax