![]() |
![]() |
![]() |
![]() |
![]() |
|
An augmented assignment operator reassigns a variable to a value that it computesvia addition, subtraction, multiplication, or divisionfrom a combination of the variable's current value and an expression's value . The following diagram illustrates how an assignment that uses an augmented assignment operator differs from an ordinary assignment:
variable name = variable name operator expression
|
*----------------*
v
variable name operator= expression
For example, you can rewrite result = result * 2 as follows:
result *= 2
Even though this shorthand gives you a perfectly valid way to multiply and
reassign, you may choose to write result = result * 2, which you see
throughout this book, on the ground that result = result * 2 stands
out more clearly as a reassignment operation.