I often see Fortran code functionally similar to the excerpt below. Had I written it, I would have used "K" instead of "J" in the write statement. Using "J" gives the same results, but is that just luck, or is it an expected behavior based on Fortran rules? I came up empty-handed searching for an applicable rule.
K = [arithmetic expression]
do J = 1, K
X(J) = [some function of J]
enddo
write(*,*) 'Number of loops: ', J