Page 74 · Robotics with the Boe-Bot
value = value - anotherValue
DEBUG "value = ", SDEC value, CR ' Display values again
√
Run the modified program and verify that
Counting and Controlling Repetitions
The most convenient way to control the number of times a piece of code is executed is
with a
loop. Here is the syntax:
FOR...NEXT
FOR Counter = StartValue TO EndValue {STEP StepValue}...NEXT
The three-dots
indicate that you can put one or more commands between the
...
and
statements. Make sure to declare a variable for use in the
NEXT
The
and
StartValue
EndValue
you see something between curly braces { } in a syntax description, it means it's an
optional argument. In other words, the
use it for a special purpose.
You don't have to name the variable "counter".
"myCounter".
myCounter
Here's an example of a
FOR...NEXT
also displays the value of the
FOR myCounter = 1 TO 10
DEBUG ? myCounter
PAUSE 500
NEXT
Example Program: CountToTen.bs2
√
Enter, save, and run CountToTen.bs2.
' Robotics with the Boe-Bot – CountToTen.bs2
' Use a variable in a FOR...NEXT loop.
' {$STAMP BS2}
' {$PBASIC 2.5}
myCounter
VAR
' Answer = -1500
value
arguments can be either numbers or variables. When
loop will work without it, but you can
FOR...NEXT
VAR
Word
loop that uses the
myCounter
variable each time through the loop.
myCounter
Word
changes from 500 to -1500.
argument.
Counter
For example, you can call it
variable for counting. It
FOR
Need help?
Do you have a question about the Boe-Bot and is the answer not in the manual?
Questions and answers