# Variables and for loops in Pluto.jl

**URL:** <https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814>\
**Category:** General Usage\
**Created:** [February 23, 2021, 12:44am UTC](https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814 "2021-02-23T00:44:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 23, 2021, 12:44am UTC](https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814/1 "2021-02-23T00:44:42Z")

</div>

I’m trying to run a loop in Pluto, but I’m having a problem with multiple deffinitions, from the way that Pluto passes on variables.

```julia
begin
	f(x)=x^2-x-20
	plot(f,4:.001:12,legend=false)
	x=11 # initial value of x # may replace with a @bind later

	for i in 1:10
		n(x)=x-(f(x)/ForwardDiff.derivative(f,x))# Newton-Rapheson formula
		plot!([x,n(x)],[0,f(n(x))],legend=false)
		plot!([n(x),n(x)],[0,f(n(x))],legend=false)# plots each itteration
		x=n(x)# recursion is used to reset x
	end
	x=11
	plot!([x,x],[0,f(x)]);vline([5]);hline([0])
end

```

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [February 23, 2021, 1:20am UTC](https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814/2 "2021-02-23T01:20:11Z")

</div>

What’s the error message that you’re getting?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 23, 2021, 1:59am UTC](https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814/3 "2021-02-23T01:59:46Z")

</div>

```julia
x not defined

```

Sorry, I wasn’t clear on that. As you can see x is deffined, but if there are multiple deffinitions of a variable, then Pluto will throw the error

```julia
Multiple definitions for x.

Combine all definitions into a single reactive cell using a `begin ... end` block.

```

Although, I have x in a begining end block

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [February 23, 2021, 2:11am UTC](https://discourse.julialang.org/t/variables-and-for-loops-in-pluto-jl/55814/4 "2021-02-23T02:11:13Z")

</div>

Just use a `let` block or a function rather than `begin`.
