我感到驚訝的是,你不能把一個數組成員作爲控制變量做循環do循環是這樣的:使用數組成員作爲控制變量FORTRAN
program test
integer, dimension(2) :: i
do i(1) = 1, 3
do i(2) = 1, 3
! anything here
write(*, *) i
end do
end do
end program
我的問題是,爲什麼它是不允許的?
編輯: 或者是允許的,但我做錯了嗎?
錯誤消息從ifort v 11.1:
test.f90(4): error #5082: Syntax error, found IDENTIFIER 'I' when expecting one of: (% : . = =>
do i(1) = 1, 3
-------^
test.f90(4): error #5082: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ;
do i(1) = 1, 3
---------------^
test.f90(5): error #5082: Syntax error, found IDENTIFIER 'I' when expecting one of: (% : . = =>
do i(2) = 1, 3
-------^
test.f90(5): error #5082: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ;
do i(2) = 1, 3
---------------^
test.f90(4): error #6535: This variable or component must be of a derived or structure type [DO]
do i(1) = 1, 3
----^
test.f90(4): error #6460: This is not a field name that is defined in the encompassing structure. [I]
do i(1) = 1, 3
-------^
test.f90(8): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement.
end do
----^
test.f90(9): error #6099: An ENDDO statement occurred without a corresponding DO or DO WHILE statement.
end do
----^
從gfortran V4.5.1 & 4.8.3的錯誤信息是:
test.f90:4.4:
do i(1) = 1, 3
1
Error: Unclassifiable statement at (1)
test.f90:5.4:
do i(2) = 1, 3
1
Error: Unclassifiable statement at (1)
test.f90:8.7:
end do
1
Error: Expecting END PROGRAM statement at (1)
test.f90:9.7:
end do
1
Error: Expecting END PROGRAM statement at (1)
您能否引用您的聲明來源? – 2014-10-28 07:37:10
我已經使用ifort v 11.1和gfortran 4.5.1&4.8.3來編譯上面的代碼。我將很快在問題中添加錯誤消息 – user3136376 2014-10-28 08:00:24