
Section 9. Programming
The following commands and logical operators are used to construct logical
expressions. CRBASIC EXAMPLE. Logical Expression Examples p. 89
demonstrate some logical expressions.
• IF
• AND
• OR
• NOT
• XOR
• IIF
Table 11. Logical Expression Examples
Sets the variable Y to 0 if the expression "X >= 5" is true, i.e. if X is greater than or equal to 5. The CR200(X) evaluates
the expression (X >= 5) and registers in system memory a -1 if the expression is true, or a 0 if the expression is false.
If X >= 5 OR Z = 2 then Y = 0
Sets Y = 0 if either X >= 5 or Z = 2 is true.
If X >= 5 AND Z = 2 then Y = 0
Sets Y = 0 only if both X >= 5 and Z = 2 are true.
"If 6" is true since "6" (a non-zero number) is returned, so Y is set to 0 every time the statement is executed.
"If 0" is false since "0" is returned, so Y will never be set to 0 by this statement.
Z will equal -1 if X > Y, or Z will equal 0 if X <= Y.
The NOT operator simply complements every bit in the word. A Boolean can only be 0 or have all of its bits set to 1.
Complementing a Boolean will turn TRUE (all bits set) to FALSE (all bits complemented to 0). Since the CR200(X)
cannot declare a variable to be a Boolean data type, IIF is used to force the logical results to either 0 or -1.
Example Program
'(a AND b) = (26 AND 26) = (&b11010 AND &b11010) =
'&b11010. NOT (&b11010) yields &b00101.
'This is non-zero, so when converted to a
'BOOLEAN, it becomes TRUE.
Public b
Public is_true
Public not_is_true
a = 26
b = a
Scan (1,Sec)
is_true = IIF(a AND b = 0,0,-1) 'This evaluates to TRUE.
not_is_true = IIF(NOT (is_true) = 0,0,-1) 'This evaluates to FALSE.
not_a_and_b = IIF(NOT (a AND b) = 0,0,-1) 'This evaluates to TRUE!
NextScan
89
Komentarze do niniejszej Instrukcji