# How to change or redefine a (global?) variable from within a while loop

**URL:** <https://discourse.julialang.org/t/how-to-change-or-redefine-a-global-variable-from-within-a-while-loop/21086>\
**Category:** New to Julia\
**Created:** [February 22, 2019, 4:50pm UTC](https://discourse.julialang.org/t/how-to-change-or-redefine-a-global-variable-from-within-a-while-loop/21086 "2019-02-22T16:50:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [February 22, 2019, 5:39pm UTC](https://discourse.julialang.org/t/how-to-change-or-redefine-a-global-variable-from-within-a-while-loop/21086/3 "2019-02-22T17:39:54Z")

</div>

> [@HelgavonLichtenstein](#):
>
> ```julia
> # here I want to stop remaking FoodWeb and place the new values of it into the previous global scope
> 
> ```

I think you are confusing changing the _value_ of a global variable with changing the _contents_ of a container. The latter operation does not change the container, only the contents.

If the above is related to [this](https://discourse.julialang.org/t/difference-between-global-and-const/21075) and [this](https://discourse.julialang.org/t/difference-between-global-and-const/21075) question, you may be better off writing a function that just modifies an array, eg

```julia
function update_foodweb!(food_web, other, arguments)
    if something
        food_web[some_coordinates, :] = updated_stuff
    end
    food_web
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-change-or-redefine-a-global-variable-from-within-a-while-loop/21086)._
