Home Segments Index Top Previous Next

312: Mainline

Augmented assignment operators reassign a variable with a value obtained by combining the variable's current value with an expression's value via addition, subtraction, multiplication, or division. The following diagram illustrates how assignment using an augmented assignment operator differs from ordinary assignment:

variable name = variable name operator expression 
                                   | 
                                   | 
                                   | 
                 *-----------------* 
                 v 
variable name operator= expression 

For example, you can rewrite result = result * 2 in this way:

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.