# A strange error

**URL:** <https://discourse.julialang.org/t/a-strange-error/138756>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 11, 2026, 8:45pm UTC](https://discourse.julialang.org/t/a-strange-error/138756 "2026-08-11T20:45:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![9herbert9](https://avatars.discourse-cdn.com/v4/letter/9/5fc32e/32.png) [@9herbert9](https://discourse.julialang.org/u/9herbert9)\
**Post date:** [August 11, 2026, 8:45pm UTC](https://discourse.julialang.org/t/a-strange-error/138756/1 "2026-08-11T20:45:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [August 11, 2026, 9:00pm UTC](https://discourse.julialang.org/t/a-strange-error/138756/2 "2026-08-11T21:00:53Z")

</div>

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

```julia-auto
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](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#scope-of-variables)

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [August 12, 2026, 7:33am UTC](https://discourse.julialang.org/t/a-strange-error/138756/3 "2026-08-12T07:33:34Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![ducksoverip](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ducksoverip/32/31967_2.png) [@ducksoverip](https://discourse.julialang.org/u/ducksoverip)\
**Post date:** [August 12, 2026, 7:57pm UTC](https://discourse.julialang.org/t/a-strange-error/138756/4 "2026-08-12T19:57:12Z")

</div>

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

```julia-auto
It was a dark and stormy night.

```

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

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 12, 2026, 9:08pm UTC](https://discourse.julialang.org/t/a-strange-error/138756/5 "2026-08-12T21:08:13Z")

</div>

> [@9herbert9](#):
>
> a simple program:  
> ss=0  
> println(ss," \<\<\<\<\<\<\<\< “)  
> for k in 3:2:20  
> print(k,” “)  
> ss=ss+k  
> println(ss,” ")  
> end

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

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

```

I get the expected result:

```julia-auto
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.
