# Help: Julia Pi example from rosettacode

**URL:** <https://discourse.julialang.org/t/help-julia-pi-example-from-rosettacode/24219>\
**Category:** New to Julia\
**Created:** [May 14, 2019, 9:02pm UTC](https://discourse.julialang.org/t/help-julia-pi-example-from-rosettacode/24219 "2019-05-14T21:02:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinMSPedersen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinmspedersen/32/8460_2.png) [@MartinMSPedersen](https://discourse.julialang.org/u/MartinMSPedersen)\
**Post date:** [May 14, 2019, 9:02pm UTC](https://discourse.julialang.org/t/help-julia-pi-example-from-rosettacode/24219/1 "2019-05-14T21:02:02Z")

</div>

Hi,  
I am totally new to Julia and I am trying various Julia examples from [Rosettacode](http://rosettacode.org/wiki/Category:Julia).  
Is there an error with the pi-calculation example [PI with Julia](http://rosettacode.org/wiki/Pi#Julia) ?

```julia
 julia pi.jl 
ERROR: LoadError: UndefVarError: digit not defined
Stacktrace:
 [1] top-level scope at /home/tusk/gits/programming/julia/pi.jl:5 [inlined]
 [2] top-level scope at ./none:0
 [3] include at ./boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at ./loading.jl:1044
 [5] include(::Module, ::String) at ./sysimg.jl:29
 [6] exec_options(::Base.JLOptions) at ./client.jl:266
 [7] _start() at ./client.jl:425
in expression starting at /home/tusk/gits/programming/julia/pi.jl:4

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 14, 2019, 9:12pm UTC](https://discourse.julialang.org/t/help-julia-pi-example-from-rosettacode/24219/2 "2019-05-14T21:12:38Z")

</div>

What you’re running into is the fact that it was written for Julia 0.6 and you’re trying to run it on Julia 1.0+. It’s also not really _using_ Julia to compute pi; it’s just using the library MPFR, but I suppose that’s alright.

To fix the error you’re hitting (and upgrade it to 1.0), you just need to put it into a local scope with a `let` statement or something similar:

```julia
julia> let
       prec = precision(BigFloat)
       spi = ""
       digit = 1
       while true
         if digit > length(spi) - 6
           prec *= 2
           setprecision(prec)
           spi = string(big(π))
         end
         print(spi[digit])
         digit += 1
       end
       end
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631

```
