Undefined /out of scope

Hello all,

I have been developing a code that executes a function using an array and now the problem started to happen when I put that function in a loop…I get the message saying that the array is not defined… I wrote the word global but it did not help
Did anyone encounter this message or error before and what was the solution ?

Thank you

dd
cc

When you have eliminated your code, whatever remains must be an empty page.

PSA
2 Likes

It’s important to read error messages carefully. Your message says that you put the global keyword in the wrong place.

Can copy and paste the part of your code where you use global? Please copy the text, not an image of the text, and put triple quotes around the code.

1 Like

Array=[1,1,1,1,1]

for i in 1:5

global Array[i]=Array[i]+1

end
ss

This is a simple code because i am afraid you get lost in the original code… but it resembles my code very much
ss

I donot get you…what do u mean by eliminated the code?

Array is already defined as a type name so you cannot make it another type. Choose another name for the variable.

This type of super-obscure communication will only be understood by those who are both very familiar with programming discussion fora and Sherlock Holmes (if I’m interpreting you correctly). It doesn’t appear very welcoming.

Don’t worry about what was written, but look at the link (it’s this one Please read: make it easier to help you). It will help you write your question in a way that makes it easier to answer.

The error message is telling you that the name Array is already defined when you start Julia:

[nils@nils-2560p /]$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> Array
Array

julia> typeof(Array)
UnionAll

this is what allows you to e.g. define an Array{Float64}(undef, 5). Change the name or your array to array (lowercase) or my_array or whatever suits you.

As an aside, stylistic convention in Julia is that capitalized identifiers (such as Array, Float64, Int etc) are used for types, while variables / instances of a type have lowercase names.

2 Likes