离散值的Fortran循环
是否有任何方法可以运行变量离散值的循环?最新版本的呢 差不多离散值的Fortran循环,fortran,fortran95,Fortran,Fortran95,是否有任何方法可以运行变量离散值的循环?最新版本的呢 差不多 for i in 1 5 9 11 31 77 是否在Unix shell脚本中使用 我不确定这是否有帮助,但您可以使用数组作为索引 integer, dimension (5) :: indx = [5, 9, 11, 31, 71] do i=1, size(indx) j=indx(i) .... end do program Console1 implicit none ! Variables IN
for i in 1 5 9 11 31 77
是否在Unix shell脚本中使用 我不确定这是否有帮助,但您可以使用数组作为索引
integer, dimension (5) :: indx = [5, 9, 11, 31, 71]
do i=1, size(indx)
j=indx(i)
....
end do
program Console1
implicit none
! Variables
INTEGER :: X(4) = (/ 1, 3, 5, 7 /)
REAL :: Y(10) = 0.0
! Body of Console1
print *, X
! 1 3 5 7
Y(X) = 10.0/X
print *, Y
! 10.0 0.0 3.33 0.0 2.00 0.0 1.428 0.0 ...
end program Console1
您也可以使用隐含的do循环来完成此操作,但必须如上所述定义值数组:
integer, dimension (5) :: indx = [5, 9, 11, 31, 71]
integer, dimension (5) :: rslt
integer, external :: func
rslt = (/ func(indx(j)), j=1,5 /)
有人正在尝试用编写程序。我同意,应该能够说
doi=(/1,3,5,7/)
,但您不能。也许可以在一个月内完成。我会调查。@ja72:你说有人试图用Fortran编写Pascal程序,这很奇怪,Pascal对在任意数字列表上“循环”的支持并不比Fortran多。此外,OP表示她从Unix shell脚本中获得了灵感。@HighPerformanceMark在pascal中,您可以使用非顺序值在emum
上循环。但它们必须是常量。