11.2. WMLScript Assignment Operators - Assigning Values to Variables
Assignment operators are used to assign a value to a variable. One of the assignment operators, =, has been used many times earlier in this WMLScript tutorial. Its usage is very straightforward and there is nothing to explain further. Here is an example:
z = 18;
The z variable contains the value 18 after execution.
WMLScript supports a number of shortcut operators that combine arithmetic operations with value assignment operations. Below is an example of the += operator:
var
z = 1;
z += 2;
After executing the above script, z contains the value 3. "z += 2;" is equivalent to "z = z + 2;".
Below is an example of the -= operator:
var
z = 5;
z -= 3;
After execution, z contains the value 2. The line "z -= 3;" is equivalent to "z = z – 3;".
The following table summarizes the shortcut assignment operators available in WMLScript:
WMLScript Operator |
Example |
Equivalent to |
+= |
x += y; |
x = x + y; |
-= |
x -= y; |
x = x - y; |
*= |
x *= y; |
x = x * y; |
/= |
x /= y; |
x = x / y; |
div= |
x div= y; |
x = x div y; |
%= |
x %= y; |
x = x % y; |
&= |
x &= y; |
x = x & y; |
|= |
x |= y; |
x = x | y; |
^= |
x ^= y; |
x = x ^ y; |
<<= |
x <<= y; |
x = x << y; |
>>= |
X >>= y; |
x = x >> y; |
>>>= |
x >>>= y; |
x = x >>> y; |
Previous Page | Page 19 of 71 | Next Page |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data