Page 72 · Robotics with the Boe-Bot
Default Value - If you do not initialize a variable, the program will automatically start by
storing the number zero in that variable. That's called the variable's default value.
The "=" sign in
value = 500
to do math with variables. Here are a couple of multiplication examples:
value = 10 * value
anotherValue = 2 * value
Example Program: VariablesAndSimpleMath.bs2
This program demonstrates how to declare, initialize, and perform operations on
variables.
√
Before running the program, predict what each
√
Enter, save, and run VariablesAndSimpleMath.bs2.
√
Compare the results to your predictions and explain any differences.
' Robotics with the Boe-Bot - VariablesAndSimpleMath.bs2
' Declare variables and use them to solve a few arithmetic problems.
' {$STAMP BS2}
' {$PBASIC 2.5}
value
VAR
anotherValue
VAR
value = 500
anotherValue = 2000
DEBUG ? value
DEBUG ? anotherValue
value = 10 * anotherValue
DEBUG ? value
DEBUG ? anotherValue
END
How VariablesAndSimpleMath.bs2 Works
This code declares two word variables,
value
is an example of an operator. You can use other operators
Word
Word
and
value
VAR
Word
command will display.
DEBUG
' Declare variables
' Initialize variables
' Display values
' Perform operations
' Display values again
.
anotherValue
' Declare variables
Need help?
Do you have a question about the Boe-Bot and is the answer not in the manual?
Questions and answers