Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!beta!unm-la!unmvax!nmtsun!john From: john@nmtsun.nmt.edu (John Shipman) Newsgroups: comp.lang.fortran Subject: Modifying iteration variables in DO loops Keywords: X3 standard FORTRAN 77 Message-ID: <1309@nmtsun.nmt.edu> Date: 1 Feb 88 19:07:01 GMT Organization: Zoological Data Processing Lines: 36 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 "DO ... = , [, ]": (1) INITIALIZATION. Compute the values of expressions , , and , and call the results M1, M2, and M3; if is omitted, set M3 to 1. Compute the number of loops: = MAX ( INT ( ( M2 - M1 + M3 ) / M3 ), 0 ) and store this value in a hidden temporary. Set to M1. (2) TEST. If is zero, branch to (5). (3) LOOP BODY. (4) MODIFICATION. Add M3 to . Decrement . Go to (2). (5) (The statement after the end of the loop) 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 I bet NOBODY has a standard-conforming compiler. From a compiler writer's point of view, this is inefficient because you have to modify both and at the bottom of the loop; this tends to make your benchmarks look bad. I bet the politics behind this decision were pretty convoluted---anybody know the history of this one? -- John Shipman/Zoological Data Processing/Socorro, New Mexico USENET: ihnp4!lanl!unm-la!unmvax!nmtsun!john ``If you can't take it, get stronger.'' --Falline Danforth