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.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...