fortran90 - Using array member as the control variable of do loop in fortran -
fortran90 - Using array member as the control variable of do loop in fortran -
i surprised cannot set array fellow member command variable of loop this:
program test integer, dimension(2) :: i(1) = 1, 3 i(2) = 1, 3 ! here write(*, *) end end end programme my question why not permitted?
edit: or permitted doing wrong?
the error message ifort v 11.1 is:
test.f90(4): error #5082: syntax error, found identifier 'i' when expecting 1 of: ( % : . = => i(1) = 1, 3 -------^ test.f90(4): error #5082: syntax error, found ',' when expecting 1 of: <end-of-statement> ; i(1) = 1, 3 ---------------^ test.f90(5): error #5082: syntax error, found identifier 'i' when expecting 1 of: ( % : . = => i(2) = 1, 3 -------^ test.f90(5): error #5082: syntax error, found ',' when expecting 1 of: <end-of-statement> ; i(2) = 1, 3 ---------------^ test.f90(4): error #6535: variable or component must of derived or construction type [do] i(1) = 1, 3 ----^ test.f90(4): error #6460: not field name defined in encompassing structure. [i] i(1) = 1, 3 -------^ test.f90(8): error #6099: enddo statement occurred without corresponding or while statement. end ----^ test.f90(9): error #6099: enddo statement occurred without corresponding or while statement. end ----^ the error message gfortran v4.5.1 & 4.8.3 is:
test.f90:4.4: i(1) = 1, 3 1 error: unclassifiable statement @ (1) test.f90:5.4: i(2) = 1, 3 1 error: unclassifiable statement @ (1) test.f90:8.7: end 1 error: expecting end programme statement @ (1) test.f90:9.7: end 1 error: expecting end programme statement @ (1)
sorry first wrong answer.
the restriction follows rules of language:
fortran 2008 (iso/iec 1539-1:2010) 8.1.6.2:
r818 loop-control is, do-variable = ...
r819 do-variable is, scalar-int-variable-name
c812 (r819) do-variable shall variable of type integer.
therefore yes, scalar variable name permitted @ position of loop command variable.
if inquire why rules of language this, have inquire authors of standard, sc22/wg5 , x3j3, guess connected necessity of syntactic unambiguity in fixed-source form. in fixed source form spaces not important , hard come unambiguous grammar.
fortran fortran90 do-loops
Comments
Post a Comment