Mathematical Assignment Expressions
In addition to the mathematical assignment operators above, steve also support mathematical assignment operators. Mathematical assignment operators are used as shortcuts to perform a calculation and update the value of a variable simultaneously, instead of as two separate steps. These expressions are useful, but since they are only shortcuts for other expressions, understanding them is not critical.
The following mathematical assignment operators are available:
-
+= -
-= -
*= -
/= -
%= -
^=
These operators are simply shortcuts for cases in which the left operand of the mathematical expression is also the location where the output of the expression will be stored. For example, the following expression pairs are equivalent:
a = a + b. # "a equals a plus b" can also be written as... a += b. # "a plus equals b" a = a - (2, 2, 2). a -= (2, 2, 2).
steve also has "increment" and "decrement" assignment operators:
-
++
-
--
As in languages like C and Perl, these operators increment and decrement a variable by one, respectively. Unlike C and Perl, these operators may only be placed after the variable. As an example, the following expression pairs are equivalent:
x = x + 1. # updates the variable x by adding 1 x++. x += 1. # does the same... x++. y = (x += 1). # a little confusing, but sets both x and y to (x + 1) y = x++. # as does this.
