Hans Zimermann
Hans Zimermann

Reputation: 330

Implicit loop for filling a dimension variable

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

Upvotes: 2

Views: 93

Answers (1)

Alexander Vogt
Alexander Vogt

Reputation: 18098

(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)]

Upvotes: 2

Related Questions