Using a Shortcut Operation to Do an Arithmetic Operation
A shortcut operation is a combination of the equal operator (=) with another operator. You can use a shortcut operation to reduce the amount of code you write. This technique does the following:
To do an operation on the value that precedes the equal operator, it uses the value that comes after the equal operator.
Saves the result in the value that precedes the equal operator.
To use a shortcut operation to do an arithmetic operation
Add an operator immediately before the equal operator.
For example, instead of writing i = i + 3, you can write i += 3.
The following table describes the shortcut operators that you can use in Siebel eScript.
Shortcut Operation | Description |
---|---|
+= |
Add a value to a variable. |
-= |
Subtract a value from a variable. |
*= |
Multiply a variable by a value. |
/= |
Divide a variable by a value. |
%= |
Return a remainder after a division operation. |
The following example uses shortcut operators:
var i;
i += 3; //i is now 5 (2 + 3). Same as i = i + 3.
i -= 3; //i is now 2 (5 - 3). Same as i = i - 3.
i *= 5; //i is now 10 (2 * 5). Same as i = i * 5.
i /= 3; //i is now 3.333...(10 / 3). Same as i = i / 3.
i = 10; //i is now 10
i %= 3; //i is now 1, (10 mod 3). Same as i = i % 3.