EasyManua.ls Logo

Parallax BASIC Stamp 2e - For

Default Icon
353 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
5: BASIC Stamp Command Reference FOR…NEXT
BASIC Stamp Programming Manual 2.0c www.parallaxinc.com Page 117
FOR…NEXT
BS1 BS2 BS2e BS2sx BS2p
FOR Counter = StartValue TO EndValue {STEP {-} StepValue} … NEXT {Counter}
FOR Counter = StartValue TO EndValue {STEP StepValue} … NEXT
Function
Create a repeating loop that executes the program lines between FOR and
NEXT, incrementing or decrementing Counter according to StepValue until
the value of the Counter variable passes the EndValue.
Counter is a variable (usually a byte or a word) used as a counter.
StartValue is a variable/constant/expression (0 65535) that
specifies the initial value of the variable (Counter).
EndValue is a variable/constant/expression (0 65535) that specifies
the end value of the variable (Counter). When the value of Counter is
outside of the range StartValue to EndValue, the FOR...NEXT loop
stops executing and the program goes on to the instruction after
NEXT.
StepValue is an optional variable/constant/expression (0 65535) by
which the Counter increases or decreases with each iteration through
the FOR…NEXT loop. On the BS1, use a minus sign (-) in front of
the StepValue to indicate a negative step. On all other BASIC
Stamps, if StartValue is larger than EndValue, PBASIC understands
StepValue to be negative, even though no minus sign is used.
Quick Facts
BS1 BS2, BS2e, BS2sx and BS2p
Max. nested
commands
8 16
To decrement
counter
variable
Set StartValue > EndValue
and enter negative
StepValue*
Set StartValue > EndValue
Counter
comparison
Exit loop if Counter exceeds
EndValue
Exit loop if Counter outside of range set by
StartValue to EndValue
* Direction (ie: increment/decrement) cannot be changed at runtime.
1
2
e
2
sx
2
p
2
1
NOTE: Expressions are not
allowed as arguments on the BS1.
1
NOTE: Use a minus sign to
indicate negative StepValues
on the
BS1.
Table 5.11: FOR…NEXT Quick
Facts.

Table of Contents

Related product manuals