Compound Assignment Operators
These combine an arithmetic operation with an assignment for shorthand.
Operator |
Equivalent To |
Example |
+= |
x = x + value |
x += 5; |
-= |
x = x - value |
x -= 3; |
*= |
x = x * value |
x *= 2; |
/= |
x = x / value |
x /= 4; |
%= |
x = x % value |
x %= 2; |