Assignment operators

Provides a reference for the syntax of assignment operators in OPL.

The equals (=) operator can be used to assign a new value to a script variable or a property.

Table 1. Assignment operator syntax
Syntax Effect
variable = expression

In scripting, all objects are assigned by reference, except strings, numbers and Booleans, which are assigned by value. See the ECMA standard for details.

Example:

x = y+1

The whole expression returns the value of expression.

value.name = expression

value[name] = expression

Assigns the value of expression to the given property.

If value does not have such a property, then if it is either an array or an object, the property is created; otherwise, an error is signalled.

Example:

car.name = "Ford" myArray[i] = myArray[i]+1

The whole expression returns the value of expression.

In addition, shorthand operators are also defined.