I have two snippets of code which I think should behave exactly the same, 
but they do not.  In the first snippet, the variable "test" only changes in 
the "i" loop.  In the second snippet, the variable "test" changes in the j 
loop which makes no sense to me.  The only difference in the two sets of 
code is the second and fifth lines in each set.

Any help would be much appreciated.

##  Snippet 1: Correct
for i in 1:4
  test = i 
  for j in 1:3
    a = test
    a=j
    println("j loop: a $a; test $test")
  end
  println("i loop: test $test")
end

## Snippet 2: Incorrect??
for i in 1:4
  test = [i] 
  for j in 1:3
    a = test
    a[1]=j
    println("j loop: a $a; test $test")
  end
  println("i loop: test $test")
end


Thanks,

Reply via email to