Poll: refactoring a chunk of legacy code

My reply to this particular code snippet is that the condition is actually superfluous and, if I may guess, only introduced because of FORTRAN 66’s one-pass do-loops (the condition was checked at the end). So instead, you could do:

do j = 1, n-1
    ...
enddo 

IF n is 1 or smaller, the number of iterations will be be zero. No check needed.

9 Likes