O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assignment Operators

Having expressions isn’t much use unless you can assign them to variables, and assigning to variables is the purpose of the assignment operators. The left side of any assignment operator must be the variable to assign.

The most common assignment operator is the simplest, which simply assigns an expression to a variable. It’s represented by =.

WMLScript also provides assignment operators that combine some other operator with the assignment. For example:

x += y

is a short form of:

x = (x + y)

There are 12 operators, each combining one of the simple binary operators with assignment: +=, -=, *=, /=, div=, %=, &=, |=, ^=, <<=, >>=, and >>>=. All the normal rules for each operator apply; so, for example, += can do string concatenation as well as addition, and /= always gives a floating-point result. Note that there are no assignment operators for the Boolean or comparison operators: if you really need that behavior, you have to write it out in full. (You probably won’t need it, though.)

The result of any assignment operation is the value that was assigned. For example:

foo (a = b)

sets a to the contents of b and then calls foo( ) with the new value of a. In the same way:

foo (a *= b)

multiplies a by the contents of b, then calls foo( ) with the new value of a.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required