sp4@beach.cis.ufl.edu (Scott Preston) (12/14/89)
Does anyone know if the fortran 8X standard Includes a loop structure Similar to the following: J=0 Repeat J=J+1 Until(line(J:J).eq.' ') This sort of routine is quite useful in amny circumstances.... If it is not included does anyone know why not?? I know this can be simulated quite easily but, the clarity is what counts here Sp4@beach.cis.ufl.edu
maine@elxsi.dfrf.nasa.gov (Richard Maine) (12/15/89)
In article <21470@uflorida.cis.ufl.EDU> sp4@beach.cis.ufl.edu (Scott Preston) writes: > Does anyone know if the fortran 8X standard Includes a loop structure > Similar to the following: > J=0 > Repeat > J=J+1 > Until(line(J:J).eq.' ') > This sort of routine is quite useful in amny circumstances.... > If it is not included does anyone know why not?? I know this > can be simulated quite easily but, the clarity is what counts here There is no explicit "repeat until" mainly because (correct me if I'm wrong) of the pressures to keep the language size from growing uncontrollably. True, this isn't a very complicated construct, but then it doesn't add much functionality either. The new DO construct does this and other jobs nicely. Your example translates into J = 0 DO J = J + 1 IF (line(J:J).eq.' ') EXIT END DO which seems reasonably clear (certainly more so than the FORTRAN 77 style code would have been). Anyway, unless you are really sure that line will always have a blank, a safer style would be something like DO J = 1 , LEN(line) IF (line(J:J).eq.' ') EXIT END DO If line has no blanks, J will be LEN(line)+1 (which is often just what you want if, for instance this code is to find the first "word" in line). I am forever finding in my Pascal coding that I want loops with multiple exit conditions like this - one normal exit if we find what was sought and one exit when we run out of data. The repeat/until and do/while structures don't encourage this. The Fortran 8x EXIT statement is much more flexible, partly because it allows the exit to be wherever it is natural instead of forcing it to be at the top or bottom. It even allows multiple places where loop termination might be wanted. A typical example is something like DO READ_LOOP READ (unit,iostat=iostat) something IF (iostat.ne.0) EXIT READ_LOOP ...various profound and presumably useful statements, perhaps even including other exit conditions depending on the data read in... END DO READ_LOOP (Yes, END= and ERR= could have handled this particular case, but they can't always and anyway, this is "cleaner"). -- Richard Maine maine@elxsi.dfrf.nasa.gov