# KeyError: key not found

**URL:** <https://discourse.julialang.org/t/keyerror-key-not-found/56813>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [March 9, 2021, 3:13pm UTC](https://discourse.julialang.org/t/keyerror-key-not-found/56813 "2021-03-09T15:13:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [March 9, 2021, 3:13pm UTC](https://discourse.julialang.org/t/keyerror-key-not-found/56813/1 "2021-03-09T15:13:52Z")

</div>

Hello everybody

Because when I try to compile this part of the model it returns this error to me:  
`KeyError: key 5 not found`

```julia
using JuMP, GLPK, GLPKMathProgInterface

ModelD = Model(GLPK.Optimizer)

t = 1:4
w = 1:2
l = 1:4

T = t
W = w
L = l
NP = 18

@variable(ModelD,eh[L,T,W]>=0)

for w = w, l = l, t = t
    if t < NP
        j1 = t+1
        h3 = @constraint(ModelD,eh[l,j1,w] <= eh[l,t,w])
        println(h3)
    end
end

```

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [March 9, 2021, 5:03pm UTC](https://discourse.julialang.org/t/keyerror-key-not-found/56813/2 "2021-03-09T17:03:58Z")

</div>

You defined `T = t = 1:4` and created the `eh` variables with that. Thus, there is no variable `eh[l,5,w]` defined. If now `t=4 < NP` you increment it to `t+1=5` in your loop and therefore cannot access `eh[l,5,w]` because it does not exist, i.e., `key 5 not found`.
