5: BASIC Stamp Command Reference – IF…THEN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 153
IF NOT x = 100 then NoCent
GOSUB Centennial ' IF x = 100 THEN GOSUB Centennial.
NoCent: ' Program continues.
Internally, the BASIC Stamp defines “false” as 0 and “true” as any value
other than 0. Consider the following instructions:
Flag VAR BIT
Flag = 1
IF Flag THEN IsTrue
DEBUG "false"
END
IsTrue:
DEBUG "true"
END
Since Flag is 1, IF...THEN would evaluate it as true and print the message
“true” on the screen. Suppose you changed the IF...THEN command to
read “IF NOT Flag THEN IsTrue.” That would also evaluate as true.
Whoa! Isn’t NOT 1 the same thing as 0? No, at least not in the 16-bit world
of the BASIC Stamp.
Internally, the BASIC Stamp sees a bit variable containing 1 as the 16-bit
number %0000000000000001. So it sees the NOT of that as
%1111111111111110. Since any non-zero number is regarded as true, NOT
1 is true. Strange but true.
The easiest way to avoid the kinds of problems this might cause is to
always use a conditional operator with IF...THEN. Change the example
above to read IF Flag = 1 THEN IsTrue. The result of the comparison will
follow IF...THEN rules. Also, the logical operators will work as they
should; IF NOT Flag = 1 THEN IsTrue will correctly evaluate to false
when Flag contains 1.
This also means that you should only use the "named" conditional logic
operators NOT, AND, OR, and XOR with IF...THEN. The conditional logic
operators format their results correctly for IF...THEN instructions. The
other logical operators, represented by symbols ~ & | and ^ do not; they
are binary logic operators.
I
NTERNAL REPRESENTATION OF
B
OOLEAN VALUES
(T
RUE VS
. F
ALSE
).
A
VOIDING ERRORS WITH
B
OOLEAN
RESULTS
.
Содержание BASIC Stamp 1
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...