Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

Compound assignment statement

Use the following syntax for the compound assignment statement.

Read syntax diagramSkip visual syntax diagram   .-,---------.
   V           |
>>---reference-+-- compound assignment operator --expression---->
 
>--;-----------------------------------------------------------><
 
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 28 lists the compound assignment operators allowed in compound assignments.
expression
Specifies an expression that is evaluated and possibly converted.

Area assignment is described in Area data and attribute.

Table 28. 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
¬= 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.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)