Compound assignment statements

This topic describes the syntax and parameters for compound assignment statements.

Syntax

Read syntax diagramSkip visual syntax diagram,reference compound assignment operator expression;

Parameters

reference
Specifies the target to be given the assignment
compound assignment operator
Specifies the operator that is applied to the reference and the evaluated expression before the assignment is made. Table 1 lists the compound assignment operators allowed in compound assignments.
expression
Specifies an expression that is evaluated and possibly converted.

For information about area assignment, see Area data and attribute.

Table 1. Compound assignment operators
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
¬= or <> 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.

See the following example:

X += 1 is the same as X = X+(1)
X *= Y+Z is the same as X = X*(Y+Z)

But the following statements are not equivalent:

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, the following statements are not equivalent:

X(f()) += 1 is not equivalent to X(f()) = X(f())+1

The function f is called only once.