contents   index   previous   next



Basic arithmetic

The arithmetic operators in ScriptEase are pretty standard.

 

=

assignment

assigns a value to a variable

+

addition

adds two numbers

-

subtraction

subtracts a number from another

*

multiplication

multiplies two numbers

/

division

divides a number by another

%

modulo

returns a remainder after division

 

The following are examples using variables and arithmetic operators.

 

var i;

i = 2;

i is now 2

i = i + 3;

i is now 5, (2+3)

i = i - 3;

i is now 2, (53)

i = i * 5;

i is now 10, (2*5)

i = i / 3;

i is now 3, (10/3) (remainder is ignored)

i = 10;

i is now 10

i = i % 3;

i is now 1, (10%3)

 

Expressions may be grouped to affect the sequence of processing. All multiplications and divisions are calculated for an expression before additions and subtractions unless parentheses are used to override the normal order. Expressions inside parentheses are processed first, before other calculations. In the following examples, the information inside square brackets, "[]," are summaries of calculations provided with these examples and not part of the calculations.

 

Notice that:

 

4 * 7 - 5 * 3;     [28 - 15 = 13]

 

has the same meaning, due to the order of precedence, as:

 

(4 * 7) - (5 * 3); [28 - 15 = 13]

 

but has a different meaning than:

 

4 * (7 - 5) * 3;   [4 * 2 * 3 = 24]

 

which is still different from:

 

4 * (7 - (5 * 3)); [4 * (-8) = 32]

 

The use of parentheses is recommended in all cases where there may be confusion about how the expression is to be evaluated, even when they are not necessary.

 


Assignment arithmetic