Ok, lets be more specific, because this behaviour seems very strange to me. I want to define some vectors in the first iteration of my loop, because there is were I find out the size they must have. A minimal example would be:
for i in 1:2
if i == 1
n = 2 # Actually this is reading problem data.
x = zeros(n)
end
println("i = ", i)
println("x[1] = ", x[1])
end
declaring x
as global does not seem reasonable to me, and this loop is thought to be inside a function, I do not want x
to be a global variable at all.
In fortran this would be something like:
double precision, allocatable :: x(:)
do i = 1, 2
if i == 1 then
n = 2
allocate(x(2))
end if
write(*,*) i, x(1)
end do
That the definition does not work with a a scalar is disturbing to me, really:
do i = 1, 2
if i == 1 then
j = 2
end if
write(*,*) i, j
end do
That this code results in an error is very, very disturbing to me.