Use the following syntax for the compound assignment statement.
|
Area assignment is described in Area data and attribute.
| Compound assignment operator | Meaning |
|---|---|
| += | Evaluate expression, add and assign |
| -= | Evaluate expression, subtract and assign |
| *= | Evaluate expression, multiply and assign |
| /= | Evaluate expression, divide and assign |
| |= | Evaluate expression, or and assign |
| &= | Evaluate expression, and and assign |
| ||= | Evaluate expression, concatenate and assign |
| **= | Evaluate expression, exponentiate and assign |
| ¬= | Evaluate expression, exclusive-or and assign |
The operator is applied to the target and source first, and then what results is assigned to the target.
For example:
| X += 1 | is the same as | X = X+(1) |
| X *= Y+Z | is the same as | X = X*(Y+Z) |
but
| X *= Y+Z | is not equivalent to | X = X*Y+Z |
In a compound assignment, any subscripts or locator expressions specified in the target variable are evaluated only once.
If f is a function and X is an array, then:
| X(f()) += 1 | is not equivalent to | X(f()) = X(f())+1 |
The function f is called only once.
The remaining text discusses the following topics: :
Examples of assignments begin in Example of moving internal data.