2

I need help to understand why I cannot compile this code

program test
 integer,dimension(1:10) :: isquares
 isquares(:) = (j**2,j=1,10)
 print*,isquares
end

However, this version is ok:

program test
 print*,(j**2,j=1,10)
end

1 Answer 1

2

(j**2,j=1,10) is a implicit loop. For an assignment, you need to convert this into an array first:

isquares(:) = [(j**2,j=1,10)]
Sign up to request clarification or add additional context in comments.

2 Comments

Right, but this feature are only available in Fortran 2003 version. jsquares(:) = [(j**2,j=1,10)] 1 Error: Fortran 2003: [...] style array constructors at (1)
Then use (/ (j**2,j=1,10) /)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.