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 is an example of an operator. You can use other operators
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
DEBUG command will display.
√ 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 Word ' Declare variables
anotherValue VAR Word
value = 500 ' Initialize variables
anotherValue = 2000
DEBUG ? value ' Display values
DEBUG ? anotherValue
value = 10 * anotherValue ' Perform operations
DEBUG ? value ' Display values again
DEBUG ? anotherValue
END
How VariablesAndSimpleMath.bs2 Works
This code declares two word variables, value and anotherValue.
value VAR Word ' Declare variables