# For syntax in @constraints

**URL:** <https://discourse.julialang.org/t/for-syntax-in-constraints/30483>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [October 30, 2019, 10:14am UTC](https://discourse.julialang.org/t/for-syntax-in-constraints/30483 "2019-10-30T10:14:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leclere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leclere/32/3644_2.png) [@leclere](https://discourse.julialang.org/u/leclere)\
**Post date:** [October 30, 2019, 10:14am UTC](https://discourse.julialang.org/t/for-syntax-in-constraints/30483/1 "2019-10-30T10:14:53Z")

</div>

Hi!

I am looking for the most elegant way of adding multiple constraints (e.g. with a for loop) in a JuMP model.

For example I would like to be able to write :

```julia
using JuMP

m = Model()
@variable(m,x[1:5])
@constraints(m, begin
    x[i+1] <= x[i] , for i in 1:4  
   x[i]+x[2i] == 1, for i in 1:2
    end)

```

Currently I’m makin a for loop and using @constraint(m,…) inside the loop. Is there another way ?

---

<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:** [October 30, 2019, 1:28pm UTC](https://discourse.julialang.org/t/for-syntax-in-constraints/30483/2 "2019-10-30T13:28:48Z")

</div>

See [Constraints · JuMP](http://www.juliaopt.org/JuMP.jl/v0.20.0/constraints/#Constraint-containers-1)

You need

```julia
@constraints(model, begin
    [i=1:4], x <= i
end)

```
