Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Boolean Logic 1
Boolean Logic
(Conditions)
ROBOTC control structures that make decisions about which pieces of code to run, such as while
loops and if-else conditional statements, always depend on a (condition) to make their decisions.
ROBOTC (conditions) are always Boolean statements. They are always either true or false at
any given moment. Try asking yourself the same question the robot does – for example, whether
the value of the Ultrasonic Sensor is greater than 45 or not. Pick any number you want for the
Ultrasonic Sensor value. The statement “the Ultrasonic Sensor’s value is greater than 45” will still
either be true, or be false.
Condition Ask yourself... Truth value
1==1
Is 1 equal to 1? True, always
0==1
Is 0 equal to 1? False, always
Condition Ask yourself... Truth value
SensorValue(sonarSensor) > 45
Is the value of the Ultrasonic
Sensor greater than 45?
True, if the current
value is more than
45 (for example, if
it is 50).
False, if the
current value is
not more than 45
(for example, if it
is 40).
Truth Values
Robots don’t like ambiguity when making decisions. They need to know, very clearly, which
choice to make under what circumstances. As a consequence, their decisions are always based
on the answers to questions which have only two possible answers: yes or no, true or false.
Statements that can be only true or false are called Boolean statements, and their true-or-false
value is called a truth value.
Fortunately, many kinds of questions can be phrased so that their answers are Boolean (true/
false). Technically, they must be phrased as statements, not questions. So, rather than asking
whether the sky is blue and getting an answer yes or no, you would state that “the sky is blue”
and then nd out the truth value of that statement, true (it is blue) or false (it is not blue).
Note that the truth value of a statement is only applicable at the time it is checked. The sky could
be blue one minute and grey the next. But regardless of which it is, the statement “the sky is
blue” is either true or false at any specic time. The truth value of a statement does not depend
on when it is true or false, only whether it is true or false right now.
Some (conditions) have the additional benet of ALWAYS being true, or ALWAYS being false.
These are used to implement some special things like “innite” loops that will never end (because
the condition to make them end can never be reached!).
Go to Reference Links