# Debugging nested loops

**URL:** https://discourse.julialang.org/t/debugging-nested-loops/18745
**Category:** General Usage
**Created:** [December 17, 2018, 2:16pm UTC](https://discourse.julialang.org/t/debugging-nested-loops/18745 "2018-12-17T14:16:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![gdestouet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdestouet/32/6175_2.png) [@gdestouet](https://discourse.julialang.org/u/gdestouet)
#### Post date: [December 17, 2018, 2:16pm UTC](https://discourse.julialang.org/t/debugging-nested-loops/18745/1 "2018-12-17T14:16:21Z")

</div>

Hello everyone,

I am trying to debug a complex function with nested for-loops by using the following trick to get some cues about which variables are causing problems

```julia
for ...
        some variables being allocated ( var1,var2 etc ... )
        try
             bug = func(var1,var2,...)
        catch err1
             quit = false
             while quit == false
                     println("debug mode : (quit=true to quit)")
                     str=readline()
                     try
                        eval(Meta.parse(str))
                     catch err2
                        println(err2)
                     end
             end

        end
end

```

I would like to get access to var1,var2,etc … without tediously adding or removing `println(vari)` in the loop, but when a bug appears and get into the while loop (“debug mode”), I can’t retrieve the for loop variables :

```julia
>run()
...
...
debug mode : (quit=true to quit) # entered in debug mode
println(var1) # trying to get the value of var1
UndefVarError(:var1) #not defined ?
debug mode : (quit=true to quit)#

```

I understand that the for and while loop define local variables but I thought that with this trick I will get access to these local variables and easily understand which variables are causing problems. How can I retrieve the whole environnement of the for loop in the first `catch` section ?

In the future I would like to use this to rapidly troubleshoot some functions, so if someone could tell me what I am doing wrong I would be very grateful !

Thank you in advance !
