# Documentation on for-loops and scoping (in and out of REPL)?

**URL:** https://discourse.julialang.org/t/documentation-on-for-loops-and-scoping-in-and-out-of-repl/21922
**Category:** General Usage
**Created:** [March 15, 2019, 6:47pm UTC](https://discourse.julialang.org/t/documentation-on-for-loops-and-scoping-in-and-out-of-repl/21922 "2019-03-15T18:47:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nickeubank](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nickeubank/32/3878_2.png) [@nickeubank](https://discourse.julialang.org/u/nickeubank)
#### Post date: [March 15, 2019, 6:47pm UTC](https://discourse.julialang.org/t/documentation-on-for-loops-and-scoping-in-and-out-of-repl/21922/1 "2019-03-15T18:47:06Z")

</div>

So I can see that issues of scoping are a HUGE subject of debate in different places, and I don’t mean to join the debates over what julia _should_ do.

Rather, I was hoping someone could lay out what the current state is (or, if all these discussions have resolved things, planned changes). I’m really struggling to figure out what behavior to expect right now…

e.g. for loops seem to not have access to variables outside the for loop in the REPL:

```julia
julia> i = 0
0

julia> for j in 1:10
           i += j
           end
ERROR: UndefVarError: i not defined
Stacktrace:
 [1] top-level scope at ./REPL[4]:2 [inlined]
 [2] top-level scope at ./none:0

```

But they do inside a function?

```julia

julia> function test()
           i = 0
           for j in 1:10
              i += j
           end
           return i
           end
test (generic function with 1 method)

julia> test()
55

```

Is this JUST about what happens in the REPL / jupyter notebooks? Is this an example of a more general rule that also applies to scoping of functions, etc. in the REPL / jupyter notebooks?

Again, no desire to join battles over _shoulds_, just want to understand what behavior to expect now in 1.1.0.

Thanks!

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 15, 2019, 6:55pm UTC](https://discourse.julialang.org/t/documentation-on-for-loops-and-scoping-in-and-out-of-repl/21922/2 "2019-03-15T18:55:56Z")

</div>

The semantics provided by the language _per se_ is well-documented:

[https://docs.julialang.org/en/v1/manual/variables-and-scoping/](https://docs.julialang.org/en/v1/manual/variables-and-scoping/)

But in IJulia, it is overridden for the global scope:

> **[GitHub - JuliaLang/SoftGlobalScope.jl: utilities for "soft" global scope in...](https://github.com/JuliaLang/SoftGlobalScope.jl)**
>
> utilities for "soft" global scope in interactive Julia environments - GitHub - JuliaLang/SoftGlobalScope.jl: utilities for "soft" global scope in interactive Julia environments

> **[GitHub - JuliaLang/IJulia.jl: Julia kernel for Jupyter](https://github.com/JuliaLang/IJulia.jl#opting-out-of-soft-scope)**
>
> Julia kernel for Jupyter. Contribute to JuliaLang/IJulia.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![nickeubank](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nickeubank/32/3878_2.png) [@nickeubank](https://discourse.julialang.org/u/nickeubank)
#### Post date: [March 15, 2019, 7:08pm UTC](https://discourse.julialang.org/t/documentation-on-for-loops-and-scoping-in-and-out-of-repl/21922/3 "2019-03-15T19:08:10Z")

</div>

ahhh, ok… that does help clarify a lot, thank you. That difference was very confusing…
