# 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 |

**Click Here for Full Table of Contents**)

- 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