Operator = (compound assignment) Foundation
Compound assignment (binary): performs an operation and assigns the resulting value to a variable.
<VarName> += <nValue> // addition
<VarName> += <cString> // string concatenation
<VarName> -= <cString> // string concatenation
<VarName> -= <nValue> // subtraction
<VarName> -= <dDate> // subtraction
<VarName> *= <nValue> // multiplication
<VarName> /= <nValue> // division
<VarName> %= <nValue> // modulus
<VarName> **= <nValue> // exponential
<VarName> ^= <nValue> // exponential
A compound assignment operator first executes the specified operation with the value of the variable <VarName> and the value of the expression and then assigns the result of the operation to the variable. The various operators are defined as follows:
Operator | Operation | Description |
---|---|---|
x += y | x := (x + y) | Inline addition, inline concatenation |
x -= y | x := (x - y) | Inline subtraction, inline concatenation |
x *= y | x := (x * y) | Inline multiplication |
x /= y | x := (x / y) | Inline division |
x %= y | x := (x % y) | Inline modulus |
x **=y | x := (x **y) | Inline exponentiation |
x ^= y | x := (x ^ y) | Inline exponentiation |
Like the inline assignment operator (:=), the compound assignment operator can be used in expressions. The expression on the right side of the operator is always evaluated first, then the specified operation is performed with the value of the variable. Finally, the resulting value is assigned to the variable on the left side of the operator. Compound assignments follow the same rules as inline assignments.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.