BASIC stamp manual v2.2
4: BASIC Stamp Architecture – Constants and Expressions
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 95
Once created, named constants may be used in place of the numbers they
represent. For example:
SYMBOL Cheers = 3 ' Number of cheers.
FOR counter = 1 TO Cheers
GOSUB Make_Cheers
NEXT
-- or --
Cheers CON 3 ' Number of cheers.
FOR counter = 1 TO Cheers
GOSUB Make_Cheers
NEXT
That code works exactly the same as the corresponding FOR…NEXT loop
in the previous example. The editor software substitutes the number 3 for
the symbol named Cheers throughout your program. Like variables, labels
and instructions, constant names are not case sensitive; CHEERS, and
ChEErs are identical to Cheers.
Using named constants does not increase the amount of code downloaded
to the BASIC Stamp, and it often improves the clarity of the program.
Weeks after a program is written, you may not remember what a
particular number was supposed to represent—using a name may jog
your memory (or simplify the detective work needed to figure it out).
Named constants also have another benefit. Suppose the “Three Cheers”
program had to be upgraded to “Five Cheers.” In the original example
you would have to change all of the 3s to 5s. Search and replace would
help, but you might accidentally change some 3s that weren’t numbers of
cheers, too. However, if you had made smart use of a named constant, all
you would have to do is change 3 to 5 in one place, the constant's
declaration:
SYMBOL Cheers = 5 ' Number of cheers.
-- or --
Cheers CON 5 ' Number of cheers.
1
All
2
1
All
2