IF...THEN - BASIC Stamp Command Reference
counterpart: If one condition or the other (but not both) is true, then the
statement is true.
Table 5.24 below summarizes the effects of the conditional logic operators.
As with math, you can alter the order in which comparisons and logical
operations are performed by using parentheses. Operations are normally
evaluated left-to-right. Putting parentheses around an operation forces
PBASIC2 to evaluate it before operations not in parentheses.
Condition A
False
True
Condition A
False
False
True
True
Condition A
False
False
True
True
Condition A
False
False
True
True
Unlike the IF...THEN commands in other BASIC's, PBASIC's IF...THEN
can only go to a label as the result of a decision. It cannot conditionally
perform some instruction, as in "IF x < 20 THEN y = y + 1." To achieve
this in PBASIC, you have to invert the logic using NOT and skip over the
conditional instruction unless the condition is met:
IF NOT x < 20 THEN NoInc
y = y + 1
NoInc:
You can also code a conditional GOSUB, as in "IF x = 100 THEN GOSUB
Centennial." In PBASIC:
Page 152 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
NOT A
True
False
Condition B
False
True
False
True
Condition B
False
True
False
True
Condition B
False
True
False
True
' Don't increment y unless x < 20.
' Increment y if x < 20.
' Program continues.
A AND B
False
False
False
True
A OR B
True
True
True
False
A XOR B
False
True
True
False
NOTE: On the BS1, parentheses
are not allowed within arguments.
Table 5.24: Conditional Logic
Operator's Truth-Table.
NOTE: The NOT operator is not
available on the BS1.
NOTE: The XOR operator is not
available on the BS1.
IF...THEN
CAN ONLY JUMP TO A
LABEL IF THE CONDITION IS TRUE
M
GOSUB.
AKING A CONDITIONAL
1
1
1
.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?