# Problem with a variable

**URL:** https://discourse.julialang.org/t/problem-with-a-variable/24954
**Category:** Performance
**Created:** [June 5, 2019, 10:03am UTC](https://discourse.julialang.org/t/problem-with-a-variable/24954 "2019-06-05T10:03:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![opihor](https://avatars.discourse-cdn.com/v4/letter/o/b5ac83/32.png) [@opihor](https://discourse.julialang.org/u/opihor)
#### Post date: [June 5, 2019, 10:03am UTC](https://discourse.julialang.org/t/problem-with-a-variable/24954/1 "2019-06-05T10:03:47Z")

</div>

Why this code doesn’t work ? I have the error : maxL not defined  
"  
maxL=0  
for j in 1:size(jobs\_in\_file,1)  
if ((ordered\_jobs[j].start\_time + ordered\_jobs[j].proc) \> ordered\_jobs[j].due)  
maxl1 = maxL + 0  
maxL = max(ordered\_jobs[j].start\_time + ordered\_jobs[j].proc - ordered\_jobs[j].due, maxL)  
end  
end  
"  
Thanks for the help!

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [June 5, 2019, 10:10am UTC](https://discourse.julialang.org/t/problem-with-a-variable/24954/2 "2019-06-05T10:10:54Z")

</div>

`for` introduces a new local scope, see [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/). See [for loop - Scope of variables in Julia - Stack Overflow](https://stackoverflow.com/questions/51930537/scope-of-variables-in-julia) for some more discussion and solutions.

See also [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

<div class="post-metadata">

### Author: ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)
#### Post date: [June 5, 2019, 2:17pm UTC](https://discourse.julialang.org/t/problem-with-a-variable/24954/4 "2019-06-05T14:17:09Z")

</div>

You could wrap the code in a let…end block. This would put `maxL` in scope.

```julia
let
    [your code here]
end
```
