BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – FOR...NEXT
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 191
FOR…NEXT
BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
FOR Counter = StartValue TO EndValue { STEP {-} StepValue }
Statement(s)
NEXT { Counter }
FOR Counter = StartValue TO EndValue { STEP StepValue }
Statement(s)
NEXT { Counter }
Function
Create a repeating loop that executes the Statement(s), one or more
program lines that form a code block, 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 BS2 models, if
StartValue is larger than EndValue, PBASIC understands StepValue to
be negative, even though no minus sign is used.
• Statement is any valid PBASIC instruction.
NOTE: Expressions are not allowed as
arguments on the BS1.
NOTE: Use a minus sign to indicate
negative StepValues on the BS1.
1
1
1
All
2