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


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page