A strange error

a simple program:
ss=0
println(ss," <<<<<<<< “)
for k in 3:2:20
print(k,” “)
ss=ss+k
println(ss,” ")
end
… creates no solution, but this error:
┌ Warning: Assignment to ss in soft scope is ambiguous because a global variable by the same name exists: ss will be treated as a new local. Disambiguate by using local ss to suppress this warning or global ss to assign to the existing global variable.
└ @ c:\Users\Besitzer\Documents\Matlab\Saturn\test.jl:20
3 ERROR: LoadError: UndefVarError: ss not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.
Stacktrace:
[1] top-level scope
@ c:\Users\Besitzer\Documents\Matlab\Saturn\test.jl:20
[2] include(mapexpr::Function, mod::Module, _path::String)
@ Base .\Base.jl:307
[3] top-level scope
@ REPL[3]:1
in expression starting at c:\Users\Besitzer\Documents\Matlab\Saturn\test.jl:18
----------- what is wrong?

Well it’s mostly in the error message you posted:

Warning: Assignment to ss in soft scope is ambiguous because a global variable by the same name exists: ss will be treated as a new local. Disambiguate by using local ss to suppress this warning or global ss to assign to the existing global variable.

In this case, if you want the loop to work with a global variable, you can write

ss=0
println(ss," <<<<<<<< ")
for k in 3:2:20
    print(k,” “)
    global ss=ss+k
    println(ss,” ")
end

There’s some helpful reading here in the documentation: Scope of Variables · The Julia Language

In addition to Mason’s clarification, it is a good idea to put non-trivial code inside functions:

function myfun(iter)
    ss=0
    println(ss, " <<<<<<<< ")
    for k in iter
        print(k, " ")
        ss = ss + k
        println(ss, " ")
    end
    return ss
end

julia> s = myfun(3:2:20)

There are at least two reasons for this. The first is that the scoping rules are saner. The more important one is that the unit of compilation in julia is the function. So code inside a function runs faster, usually much faster.

Others have already given you good advice on the error, but for future reference, it’s good etiquette to post code/terminal outputs in raw format. This can be done for single words/phrases by enclosing them in backticks (`), so that `code` becomes code, for example.

Entire text blocks can be enclosed in triple backticks, so that

```
It was a dark and stormy night.
```
becomes

It was a dark and stormy night.

Anyways, welcome to the forum, and best of luck!

I don’t quite understand the problem. If I do:

ss=0
println(ss," <<<<<<<< ")
for k in 3:2:20
    print(k," ")
    global ss=ss+k
    println(ss," ")
end

I get the expected result:

0 <<<<<<<< 
3 3 
5 8 
7 15 
9 24 
11 35 
13 48 
15 63 
17 80 
19 99 

Perhaps you had other code in your session? Anyways, if I copy your code from your post, I get an error message due to some use of non-standard quotation symbols.