Foreach Operator (Solver Foundation)
TOC
Collapse the table of content
Expand the table of content

Foreach Operator (Solver Foundation)

Solver Foundation 3.0

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

Foreach[iters..., expr]

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.

Show:
© 2016 Microsoft