# Can't Change Vector inside loop

**URL:** <https://discourse.julialang.org/t/cant-change-vector-inside-loop/15238>\
**Category:** New to Julia\
**Created:** [September 20, 2018, 4:01pm UTC](https://discourse.julialang.org/t/cant-change-vector-inside-loop/15238 "2018-09-20T16:01:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrey.Borzunov](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@Andrey.Borzunov](https://discourse.julialang.org/u/Andrey.Borzunov)\
**Post date:** [September 20, 2018, 4:01pm UTC](https://discourse.julialang.org/t/cant-change-vector-inside-loop/15238/1 "2018-09-20T16:01:34Z")

</div>

I’m confused with the next error:

```julia
julia> A = ones(10);

julia> A = A - 0.25.*A
10-element Array{Float64,1}:
 0.75
 0.75
 0.75
 0.75
 0.75
 0.75
 0.75
 0.75
 0.75
 0.75

julia> for i = 1:2
       A = A - 0.25.*A
       end
ERROR: UndefVarError: A not defined
Stacktrace:
 [1] top-level scope at ./REPL[3]:2 [inlined]
 [2] top-level scope at ./none:0

```

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [September 20, 2018, 4:06pm UTC](https://discourse.julialang.org/t/cant-change-vector-inside-loop/15238/2 "2018-09-20T16:06:26Z")

</div>

You need to declare A global in the loop, since it’s a global variable being modified.

If this code was in a function, this would not be necessary. This behavior is new in 0.7
