# Loops "for" and "while" in JuMP

**URL:** <https://discourse.julialang.org/t/loops-for-and-while-in-jump/31657>\
**Category:** Optimization (Mathematical)\
**Created:** [November 29, 2019, 12:35pm UTC](https://discourse.julialang.org/t/loops-for-and-while-in-jump/31657 "2019-11-29T12:35:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jadosfer](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@jadosfer](https://discourse.julialang.org/u/jadosfer)\
**Post date:** [November 29, 2019, 12:35pm UTC](https://discourse.julialang.org/t/loops-for-and-while-in-jump/31657/1 "2019-11-29T12:35:29Z")

</div>

Hi, I’m working with JuMP and I want to modify expressions in my model within a while or for loop, and I have problems using the “input” command. When I modify a Julia variable, which is a coefficient in a JuMP NLexpression and de code reload the JuMP model, the error appears. For example:

for i=1:2

model = Model(with\_optimizer(Ipopt.Optimizer))

variable(model, empleo, start = 0.1)

…

@NLexpression(model, er1, -empleo + c1\_0 + c1\_1 \* out + c1\_2 \* stock\_k + c1\_3 \*((1+wage)/(1+domP) -1) + c1\_4 \* empleo0)

…

@NLobjective(model, Min, er1^2 +er2^2)

optimize!(model)

println(“El Empleo creció:”,value(empleo))

c1\_1= parse(Float64, input2("si desea modificar la inversión pública ingrese la tasa de variación y presione enter: "))

end

c1\_1 is a coefficient in the first NLexpression

thanks in advance!

---

<div class="post-metadata">

**Author:** ![Libbum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/libbum/32/3935_2.png) [@Libbum](https://discourse.julialang.org/u/Libbum)\
**Post date:** [November 29, 2019, 8:51pm UTC](https://discourse.julialang.org/t/loops-for-and-while-in-jump/31657/2 "2019-11-29T20:51:15Z")

</div>

I’m not 100% sure about what you’re asking here, but it seems like you want to allow a user to input a new value to `c1_1`, then solve the model again?

If so, you need to make `c1_1` a [NLParameter](http://www.juliaopt.org/JuMP.jl/v0.19.2/nlp/#Nonlinear-Parameters-1).

Perhaps something like this:

```julia
@NLparameter(model, c1_1 == 0.1)

for i=1:2 

...

user_value = parse(Float64, input2("si desea modificar la inversión pública ingrese la tasa de variación y presione enter: "))

set_value(c1_1, user_value)

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 30, 2019, 6:22pm UTC](https://discourse.julialang.org/t/loops-for-and-while-in-jump/31657/3 "2019-11-30T18:22:35Z")

</div>

Please take the time to read [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757).

In particular, it is easier to help if you can make a minimal reproducible example that demonstrates the error.

If you want to modify coefficients in a nonlinear expression, @Libbum is correct, parameters are the solution.
