julia> function my_fu()
global j
println(j)
end
my_fu (generic function with 1 method)
julia> for j=1:3
global j
my_fu()
end
ERROR: syntax: variable "j" declared both local and global
You are implicitly declaring j
locally in your for
loop.
Try
for i ∈ 1:3
global j = i
my_fu()
end
1 Like
Works, why ?
∈== in
?
It’s just an alternate syntax that’s available in Julia. It is exactly equivalent to in
. Note that if you are using a Julia (or other latex-to-unicode) plugin on your editor you can just type in \in
, either hit tab or space, and the replacement will be made for you.
Of course, this has nothing to do with why your original code was failing.
2 Likes