Disjunction
Also known as the \or operator", disjunction in RobotC is represented by '||'. TwoBoolean values are combined syntactically as
p || q;
and the result is a new Boolean value. The result depends on the values of p and q and
follows the rules outlined in Table 5.2.
5.1.3 Negation
Also known as the \not operator", negation in RobotC is represented by '~'. Unlike the
conjunction and disjunction operators, the negation operator only acts on a single boolean
value as
~p;
and the result is a new Boolean value that is simply the opposite of the value of p. If p
is false, then ~p is true. If p is true, then ~p is false. Additional information about
Boolean algebra in RobotC is available here1.
5.1.4 Boolean Expressions
It is surprising how complicated Boolean algebra can get given the simple and limited nature
of its variables and operations. A Boolean expression is any combination of Boolean
variables and operations that can be evaluated to a Boolean value if all the values of the
variables are known. For convenience, Boolean expressions may also include parentheses to
control the order of evaluation. Negation takes precedence over conjunction and disjunction.
In the case of ties, expressions are evaluated from left to right. Consider the snippet of
instruction.
bool p,q,r,s;
p= true ; q= false ; r= true ;
s =~( p||q) && (q||r) && (r&&p);
Listing 5.1: A compound Boolean expression. At the end of the block, s has the value false.
No comments:
Post a Comment