title: Variable defined outside a while loop not defined inside?
body: <p>I'm attempting to write a Newton-Raphson solver in Julia. The Newton-Raphson method is shown in this image. </p>
  
  <p><a href="https://i.stack.imgur.com/LPp0B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LPp0B.png" alt="Newton-Raphson solver equation"></a></p>
  
  <pre><code>f(x) = x^2.5 - 3x^1.5 - 10
  fprime(x) = 2.5x^1.5 - 4.5x^0.5
  x = zeros(1000)
  x[1] = 10
  δ = 1 # a relatively large number compared to what we want the error to be 
  iter = 1
  while δ &gt; 1e-6
      x[iter + 1] = x[iter] - f(x[iter])/fprime(x[iter])
      iter += 1
      δ = abs(x[iter] - x[iter + 1])
  
      if iter == 100 
          break
      end
  end
  println("The solution is ")
  show(x[iter])
  </code></pre>
  
  <p>However, when I run the code, I get an error saying <code>iter</code> is not defined, even though I defined it just before the start of the loop. Is there some scoping problem I'm completely missing? </p>
  
  <pre><code>ERROR: LoadError: UndefVarError: iter not defined
  Stacktrace:
   [1] top-level scope at /Users/natemcintosh/Documents/Julia/Learning_julia.jl:11 [inlined]
   [2] top-level scope at ./none:0
   [3] include_string(::Module, ::String, ::String) at ./loading.jl:1002
   [4] (::getfield(Atom, Symbol("##120#125")){String,String,Module})() at /Users/natemcintosh/.julia/packages/Atom/Pab0Z/src/eval.jl:120
   [5] withpath(::getfield(Atom, Symbol("##120#125")){String,String,Module}, ::String) at /Users/natemcintosh/.julia/packages/CodeTools/8CjYJ/src/utils.jl:30
   [6] withpath at /Users/natemcintosh/.julia/packages/Atom/Pab0Z/src/eval.jl:46 [inlined]
   [7] #119 at /Users/natemcintosh/.julia/packages/Atom/Pab0Z/src/eval.jl:117 [inlined]
   [8] hideprompt(::getfield(Atom, Symbol("##119#124")){String,String,Module}) at /Users/natemcintosh/.julia/packages/Atom/Pab0Z/src/repl.jl:76
   [9] macro expansion at /Users/natemcintosh/.julia/packages/Atom/Pab0Z/src/eval.jl:116 [inlined]
   [10] (::getfield(Atom, Symbol("##118#123")){Dict{String,Any}})() at ./task.jl:85
  in expression starting at /Users/natemcintosh/Documents/Julia/Learning_julia.jl:10
  </code></pre>
  
  <p>I've tried printing <code>x</code> at the beginning of the <code>while</code> loop and it knows what <code>x</code> is, but thinks <code>iter</code> is undefined. </p>