【发布时间】:2012-03-20 16:35:49
【问题描述】:
我使用 Fortran,我想知道是否可以制作类似的东西
do i = array
write (*,*) i
end do
其中数组是不一定有序的整数列表。
【问题讨论】:
我使用 Fortran,我想知道是否可以制作类似的东西
do i = array
write (*,*) i
end do
其中数组是不一定有序的整数列表。
【问题讨论】:
我会引入第二个索引来遍历数组的元素:
program test
implicit none
integer, dimension(6) :: A
integer, dimension(10) :: B
integer :: i, j
A = (/ 1, 3, 4, 5, 8, 9 /)
B = (/ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 /)
do j = 1, size(A)
i = A(j)
write(*,*) i, B(i)
end do
end program test
【讨论】:
你的意思是你想写一个名为other_array的数组的一些元素,但不是全部,并且i应该依次取任意值?换句话说你不想打印
do i = 1, size(other_array,1)
write(*,*) other_array(i)
end do
但是类似
array = [1,3,4,2,3,7,8,8,12]
write(*,*) another_array(array)
哪个会写入array 中指定的another_array 的元素?这称为数组下标。我还没有测试过这个,我现在要出去所以不会。
【讨论】: