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

Increment and Decrement Operators

WMLScript provides four operators as a conveniently short form for the common task of adding or subtracting one from a variable.

The preincrement and predecrement operators, written as:

            ++var

and:

            --var

respectively, each attempt to convert the contents of the variable to an integer or floating-point value, add one to it (++) or subtract one from it (--), and store it back into the variable. The result of the operator is the new value of the variable.

The postincrement and postdecrement operators, written as:

            var++

and:

            var--

respectively, behave slightly differently. They still change the value of the variable, but the result of the operator is the value of the variable before the change.

For example, suppose that variable a contains the value integer 42, b contains integer 0x7FFFFFFF (the largest valid positive integer value), c contains floating-point 2.3, d contains string "1e2", and e contains string "foo":

a++ gives integer 42 and sets a to integer 43
++a gives integer 43 and sets a to integer 43
a-- gives integer 42 and sets a to integer 41
--a gives integer 41 and sets a to integer 41
b++ gives integer 0x7FFFFFFF and sets b to invalid (overflow)
++b gives invalid and sets b to invalid (overflow again)
c++ gives floating-point 2.3 and sets c to floating-point 3.3
--c gives floating-point 1.3 and sets c to floating-point 1.3
d-- gives string "1e2" and sets d to floating-point 99.0
++d gives floating-point 101.0 and sets d to floating-point ...

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