在fortran中使用do循环时遇到问题,
REAL W,V,X
DO 50 W = 0.5,5.0,0.5
DO 50 V = 10.0,1000.0,10.0
DO 50 X = 1.0,10,1.0
C=(W*V*X)/1000.0
WRITE(*,*) W,V,X,C
50 CONTINUE
STOP
END
如果我给出了这个,它表明在 do 循环中只需要使用整数,有没有办法在 do 循环中给出整数或任何其他方式来做到这一点?
在fortran中使用do循环时遇到问题,
REAL W,V,X
DO 50 W = 0.5,5.0,0.5
DO 50 V = 10.0,1000.0,10.0
DO 50 X = 1.0,10,1.0
C=(W*V*X)/1000.0
WRITE(*,*) W,V,X,C
50 CONTINUE
STOP
END
如果我给出了这个,它表明在 do 循环中只需要使用整数,有没有办法在 do 循环中给出整数或任何其他方式来做到这一点?
使用整数作为循环索引
REAL W,V,X
INTEGER I,J,K
DO 50 I = 1,10
DO 50 J = 1,100
DO 50 K = 1,10
W = 0.5 * I
V = 10.0 * J
X = 1.0 * K
C=(W*V*X)/1000.0
WRITE(*,*) W,V,X,C
50 CONTINUE
STOP
END
You should be able to accomplish the same thing by incrementing a real variable by adding your step value, and using an if then to exit the loop. Clunky, but should work.
The last time I programmed in Fortran, I used punch cards and an IBM-360, so I'm not going to pretend I remember the syntax.