# Why can't I access the variable value after a loop

**URL:** <https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860>\
**Category:** New to Julia\
**Tags:** question, loops\
**Created:** [June 14, 2021, 3:19am UTC](https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860 "2021-06-14T03:19:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Jara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paolo_jara/32/25685_2.png) [@Paolo\_Jara](https://discourse.julialang.org/u/Paolo_Jara)\
**Post date:** [June 14, 2021, 3:19am UTC](https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860/1 "2021-06-14T03:19:41Z")

</div>

Hi, I use Pluto to run Julia, but I have a problem wanting to get the value of the variable x\_t1 out of the loop. Additional, is there a way to use `print()` and get the value inside the loop in Pluto?

```julia
begin
function raiz(x_t, ϵ, n)
	for i=1:n
		x_t1=x_t
		x_t=(x_t+0.2)^0.5
		if abs(x_t1-x_t)<=ϵ
			break
		end
	end
		return x_t1
	end
raiz(0.4, 1.e-10, 100)
end

UndefVarError: x_t1 not defined

```

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [June 14, 2021, 3:25am UTC](https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860/2 "2021-06-14T03:25:39Z")

</div>

Do a search for “local scope” and/or “global scope” inside the Julia manual, e.g. [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/)

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [June 14, 2021, 4:16am UTC](https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860/3 "2021-06-14T04:16:39Z")

</div>

Just define `x_t1` outside the loop, for instance by assigning `x_t1 = 0` before the `for`.

---

<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:** [June 14, 2021, 4:50am UTC](https://discourse.julialang.org/t/why-cant-i-access-the-variable-value-after-a-loop/62860/4 "2021-06-14T04:50:21Z")

</div>

The `local` keyword introduces a variable name in a scope. If you use it outside the loop, the variable will be available also here. No need to declare to variable global or otherwise.
