Mod
Operator Mod
Return the modulo of a number
Syntax A = B Mod 2
Remarks
Mod will return the integer remainder of an integer division.
Some rules:
x Mod 0 will cause an error. (Divide by zero)
x Mod 1 will return 0, there can be no remainder.
x Mod n will return a value in the range 0 to n-1.
If x is a floating point number (has numbers to the right of the decimal place), MOD will round x to an integer prior to doing an integer divide.
Modulo is often used to limit values to a certain range.
For instance, if you want to receive only the last 2 digits from a year, (Y2K is over, don't worry about it.), then year MOD 100 would always yield a value from 0 to 99.
MOD has very low precedence, this means for clarity and proper interpretation, you should use parentheses around the modulo statement to enforce precedence, especially when mixing it with a high precedence operator like NOT.
See Also:
Example Script
NUMBER i
FOR i = 1 TO 100
IF NOT(i MOD 3)
PRINT i; " is a multiple of 3 ";
IF NOT(i MOD 2) THEN
PRINT "and a multiple of 6"
ELSE
ENDIF
ENDIF
NEXT
Script Output
3 is a multiple of 3
6 is a multiple of 3 and a multiple of 6
9 is a multiple of 3
12 is a multiple of 3 and a multiple of 6
15 is a multiple of 3
18 is a multiple of 3 and a multiple of 6
21 is a multiple of 3
24 is a multiple of 3 and a multiple of 6
27 is a multiple of 3
30 is a multiple of 3 and a multiple of 6
33 is a multiple of 3
36 is a multiple of 3 and a multiple of 6
39 is a multiple of 3
42 is a multiple of 3 and a multiple of 6
45 is a multiple of 3
48 is a multiple of 3 and a multiple of 6
51 is a multiple of 3
54 is a multiple of 3 and a multiple of 6
57 is a multiple of 3
60 is a multiple of 3 and a multiple of 6
63 is a multiple of 3
66 is a multiple of 3 and a multiple of 6
69 is a multiple of 3
72 is a multiple of 3 and a multiple of 6
75 is a multiple of 3
78 is a multiple of 3 and a multiple of 6
81 is a multiple of 3
84 is a multiple of 3 and a multiple of 6
87 is a multiple of 3
90 is a multiple of 3 and a multiple of 6
93 is a multiple of 3
96 is a multiple of 3 and a multiple of 6
99 is a multiple of 3