11. WMLScript Operators

WMLScript provides a large number of operators that help us do many different kinds of things. For example, we use the + operator to add two numbers together. In the following sections, we will introduce to you some of the more commonly used operators. Many of them are used in the same way as in C++, Java, JavaScript, etc. You may skip some parts if you are familiar to them.

11.1. WMLScript Arithmetic Operators - Performing Math Operations

WMLScript arithmetic operators can help you perform various kinds of math operations.

11.1.1. Basic Math Operations - Addition, Subtraction, Multiplication, Division, Finding Remainders

Basic math operations like addition, subtraction and multiplication are done using the +, - and * operators. For example:

z = 1 + 2;

z has the value 3.

z = 5 - 3;

z has the value 2.

z = 2 * 3;

z has the value 6.

Two operators, / and div, can be used to perform division. The result returned by the / operator is of the float type and that returned by the div operator is of the integer type. Here is a WMLScript example that illustrates the difference between them:

x = 3 / 2;
y = 3 div 2;

After execution, x has the floating-point value 1.5 while y has the integral value 1.

To find the remainder of division, use the % operator. For example:

x = 3 % 2;
y = 20 % 2;
z = 20 % 3;

After execution, x has the value 1, y has the value 0 and z has the value 2.

Previous Page Page 16 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