Why I don't obtain an output variable in a for loop?

Hello

I’m struggling with a for loop in julia.
My WAVFilesList is a vector of five strings.
I don’t understand why when I’m doing the following command I do not obtain a WAVfilenames variable in each passage of the loop. WAVfilenames simply do not exist.

for i in 1:length(WAVFilesList)
WAVfilenames=WAVFilesList[i];
end

However, If I copy-paste just that line of code (WAVfilenames=WAVFilesList[i]) and change i for a number I can obtain WAVfilenames variable.

What am I missing here?

Thanks in advance

It may be a little long, but https://docs.julialang.org/en/v1/manual/variables-and-scoping/#scope-of-variables should explain it. In the documentation in this link, you can find:

julia> for i = 1:3
           x = "hello" # new local
           println(x)
       end
hello
hello
hello

julia> x
ERROR: UndefVarError: `x` not defined

which is like the example you gave, and is the result of soft scoping, explained in the linked manual page.

Hello @Dan ,
I read it already and I defined the variable outside the loop, however I still have the same problem.
Thanks in advance

I guess I solved it.
I just add: global behind the name of my variable and it seems its working.
Thank you