Foreach Operator (Solver Foundation)

Evaluates an expression for each possible combination of values of some iterator variables, and returns all the results.

Foreach[iters..., expr]

Example

Plus[Foreach[{p, Products}, x[p]]]
Plus[Foreach[{p, Products}, {s, Sources}, x[p, s]]]
Max[Foreach[{i, 5}, x[i]]]

Each iterator can be one of these forms:

  • {x, s} where s is a Set parameter. x is an iterator variable that takes the value of each element of the set in turn.

  • {x, n} where n is a number. x is an iterator variable that takes the values 0, 1, …, n-1.

  • {x, m, n} where m and n are numbers. x is an iterator variable that takes the values m, m+1, …, n-1.

  • {x, m, n, j} where m, n, and j are numbers. x is an iterator variable that takes the values m, m+j, …, n-j.

  • {x, {a, b, … z}} where x is an iterator variable that takes the values a, b, …, z.

If no iterators are specified, Foreach just evaluates expr.

See Also

Concepts

Optimization Modeling Language (OML)