13.4 Augmented Assignment Operators
In an earlier section we looked at the basic assignment operator (=). Kotlin provides a number of operators designed to combine an assignment with a mathematical or logical operation. These are primarily of use when performing an evaluation where the result is to be stored in one of the operands. For example, one might write an expression as follows:
x = x + y
The above expression adds the value contained in variable x to the value contained in variable y and stores the result in variable x. This can be simplified using the addition augmented assignment operator:
x += y
The above expression performs exactly the same task as x = x + y but saves the programmer some typing.
Numerous augmented assignment operators are available in Kotlin. The most frequently used of which are outlined in the following table:
Operator |
Description |
... |