Phrase reversals: Difference between revisions

Line 581:
Would be rather more structured and involve fewer GO TOs and their labels, but alas, modern Fortran specifies that there is no specification as to whether or not both terms of an expression such as (A '''and''' B) will always be evaluated or instead there will be a shortcut: if A is ''false'' then the B term is ignored. And here, the A term checks whether or not L1 is within bounds and if it is not, then the B term should not be evaluated, not just because of the waste of effort but because to do so might involve accessing outside the definition of ATXT. As when the scan chases through the trailing spaces. One could make the array one longer, or rather, <code>L = LEN(TEXT) - 1</code> for this case but that would be messy, require explanation, be easily forgotten, and, typical ad-hoc testing would be unlikely to detect the mistake.
 
Alternatively, a GO TO can be removed from view by using EXIT in its place: <lang Fortran> DO L1 = L1,L
IF (ATXT(L1).GT." ") EXIT
END DO</lang> Except that this relies on the index variable retaining its value on exiting the loop, either as fingering the first non-blank or, being L + 1. This expectation is frowned upon in some quarters.
1,220

edits