# How to print multiple values in a loop

I want to print my output in Julia, I have written it in the form presented below but I want to use a for loop to make it more concise.
Any help on how to write the code below using for loop will be appreciated please.

@show objective_value(model)
@show value(w)
@show value(w)
@show value(w)
@show value(w)
@show value(w)
@show value(x)
@show value(x)
@show value(x)
@show value(x)
@show value(x)
@show value(X)
@show value(y)

Please make a new post, rather than commenting on an old one.

Just write a for loop over the indices?

``````for I in 1:5
@show value(x[I])
end
``````
1 Like

I tried this but am not getting it rightly.
This is the output I get when I run the code

value(w[I]) = 0.0
value(w[I]) = 0.0
value(w[I]) = 0.0
value(w[I]) = 0.0
value(w[I]) = 0.0

I want it to display as w1, w2, w3 …w5.

I also want to write the codes below using a for loop.

Kindly help me out.

# Rewrite using a for loop

@constraint(model, X^2 + y^2 - d-2X-2y <= -2)

@constraint(model, X^2 + y^2 - d-2X-8y <= -17)

@constraint(model, X^2 + y^2 - d-8X-8y <= -32)

``````@show objective_value(model)
for i in 1:5
@show value(w[i])
end
for i in 1:5
@show value(x[i])
end
@show value(X)
@show value(y)
``````
``````for i in 1:5
println("x[\$i] = ", value(x[i]))
end
``````
1 Like

Thank you very much.
This works now and my problem is solved.
To interpolate the value of `i` into the string.