Section 4. CRBasic – Native Language Programming
4-7
4.5 Logical Expression Evaluation
4.5.1 What is true?
Several different words get used to describe a condition or the result of a test.
The expression, X>5, is either
true
or
false
. However, when describing the
state of a port or flag,
on
or
off
or
high
or
low
sounds better. In CRBasic there
are a number of conditional tests or instruction parameters the result of which
may be described with one of the words in Table 4.5-1. The CR9000 evaluates
the test or parameter as a number; 0 is false, not equal to 0 is true.
TABLE 4.5-1. Synonyms for True and False
Predefined Constant True (-1) False (0)
Synonym High
Low
Synonym On
Off
Synonym Yes
No
Synonym Trigger
Do
Not
Trigger
Number
≠
0
0
Digital port
5 Volts
0 Volts
4.5.2 Expression Evaluation
Conditional tests require the CR9000 to evaluate an expression and take one
path if the expression is true and another if the expression is false. For
example:
If X>=5 then Y=0
will set the variable Y to 0 if X is greater than or equal to 5.
The CR9000 will also evaluate multiple expressions linked with
and
or
or
.
For example:
If X>=5 and Z=2 then Y=0
will only set Y=0 if both X>=5 and Z=2 are true.
If X>=5 or Z=2 then Y=0
will set Y=0 if either X>=5 or Z=2 is true (see And and Or in Section 9). A
condition can include multiple
and
and
or
links.
4.5.3 Numeric Results of Expression Evaluation
The CR9000 expression evaluator evaluates an expression and returns a
number. A conditional statement uses the number to decide which way to
branch. The conditional statement is false if the number is 0 and true if the
number is not 0. For example:
If 6 then Y=0,
is always true, Y will be set to 0 any time the conditional statement is
executed.
If 0 then Y=0
is always false, Y will never be set to 0 by this conditional statement.
The CR9000 expression evaluator evaluates the expression, X>=5, and returns
-1, if the expression is true, and 0, if the expression is false.
W=(X>Y)
will set W equal to -1 if X>Y or will set W equal to 0 if X<=Y.
Summary of Contents for CR9000
Page 6: ...CR9000 Table of Contents iv This is a blank page ...
Page 22: ...CR9000 Overview OV 16 This is a blank page ...
Page 26: ...Section 1 Installation 1 4 CR9000 FIGURE 1 1 3 CR9000 Battery Pack ...
Page 72: ...Section 3 CR9000 Measurement Details 3 28 This is a blank page ...
Page 88: ...Section 5 Program Declarations 5 6 This is a blank page ...
Page 217: ...This is a blank page ...