# How to access/ change a parameter inside loop?

**URL:** <https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747>\
**Category:** General Usage\
**Tags:** question, local, for-loop\
**Created:** [October 14, 2022, 5:12pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747 "2022-10-14T17:12:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_comen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_comen/32/33609_2.png) [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Post date:** [October 14, 2022, 5:12pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/1 "2022-10-14T17:12:12Z")

</div>

As variables are local inside while/ for loop in Julia, I was wondering how to see the changes that happen inside loop and then use the values after changes??

For example, consider a very simple implementation of raising five to the power of three:

I did try this:

```julia
x1 = 5; n1 = 3; global result = 1;

for i in range(1,n1)
	result = result* x1
end
result

```

It will show the value of “1” for result. And once using `global result = result* x1` inside for loop, it will return `Multiple definitions for result.`

Why is this? And how to save changes?

---

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [October 14, 2022, 5:33pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/2 "2022-10-14T17:33:21Z")

</div>

Your code works on my pc: result is 125

---

<div class="post-metadata">

**Author:** ![Mike\_comen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_comen/32/33609_2.png) [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Post date:** [October 14, 2022, 6:55pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/3 "2022-10-14T18:55:30Z")

</div>

Really!! How come?? Did I do something wrong?

@qwerty this is what I get:

![image](https://global.discourse-cdn.com/julialang/original/3X/7/8/78f35d1908179470d26e472d2e01ec76e3ae81d7.png)

---

<div class="post-metadata">

**Author:** ![Mike\_comen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_comen/32/33609_2.png) [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Post date:** [October 14, 2022, 7:01pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/4 "2022-10-14T19:01:18Z")

</div>

> [@Mike\_comen](#):
>
> ```julia
> x1 = 5; n1 = 3; global result = 1;
> 
> for i in range(1,n1)
> result = result* x1
> end
> result
> 
> ```

could this be a bug of Pluto? because now that I did the same inside repl it does return 125!

---

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [October 14, 2022, 7:20pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/5 "2022-10-14T19:20:06Z")

</div>

![cell](https://global.discourse-cdn.com/julialang/original/3X/6/6/6695c24ddbc175c632c6c3c9b6071d2a83cd9d23.jpeg)

---

<div class="post-metadata">

**Author:** ![Mike\_comen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_comen/32/33609_2.png) [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Post date:** [October 14, 2022, 7:26pm UTC](https://discourse.julialang.org/t/how-to-access-change-a-parameter-inside-loop/88747/6 "2022-10-14T19:26:13Z")

</div>

Yes, thaks @qwerty . with begin and end it gives the correct one.  
But, isn’t it strange why in separate cell it’s not correct?
