28125 Parallax Inc, 28125 Datasheet - Page 88

TEXT ROBOTICS

28125

Manufacturer Part Number
28125
Description
TEXT ROBOTICS
Manufacturer
Parallax Inc
Datasheet

Specifications of 28125

Title
Robotics with the Boe-Bot
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
Counting and Controlling Repetitions
The most convenient way to control the number of times a piece of code is executed is
with a
The three-dots
and
The
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”.
Here’s an example of a
also displays the value of the
Example Program: CountToTen.bs2
' Robotics with the Boe-Bot – CountToTen.bs2
' Use a variable in a FOR...NEXT loop.
' {$STAMP BS2}
' {$PBASIC 2.5}
myCounter
NEXT
StartValue
FOR…NEXT
value = value - anotherValue
DEBUG "value = ", SDEC value, CR ' Display values again
Run the modified program and verify that
FOR Counter = StartValue TO EndValue {STEP StepValue}…NEXT
myCounter
FOR myCounter = 1 TO 10
NEXT
Enter, save, and run CountToTen.bs2.
statements. Make sure to declare a variable for use in the
DEBUG ? myCounter
PAUSE 500
...
loop. Here is the syntax:
and
indicate that you can put one or more commands between the
VAR
EndValue
FOR…NEXT
VAR
myCounter
Word
arguments can be either numbers or variables. When
loop that uses the
Word
FOR…NEXT
variable each time through the loop.
' Answer = -1500
value
loop will work without it, but you can
myCounter
For example, you can call it
changes from 500 to -1500.
variable for counting. It
Counter
argument.
FOR

Related parts for 28125