FOR...NEXT - BASIC Stamp Command Reference
Reps
VAR
BYTE
FOR Reps = 10 to 300
DEBUG DEC ? Reps
NEXT
Reps still rolls over to 0, as before, however, this time it is outside the range
of 10 to 255. The loop stops, leaving Reps at 0. Note that this code is still in
error since Reps will never reach 300 until it is declared as a WORD.
Demo Program (FORNEXT.bas)
' This example uses a FOR...NEXT loop to churn out a series of sequential squares
' (numbers 1, 2, 3, 4... raised to the second power) by using a variable to set the
' FOR...NEXT StepValue, and incrementing StepValue within the loop. Sir Isaac Newton
' is generally credited with the discovery of this technique.
'{$STAMP BS1}
SYMBOL
Square
= B0
SYMBOL
StepSize = B1
loop.
StepSize = 1
Square = 1
FOR Square = 1 TO 250 STEP StepSize
DEBUG Square
StepSize = StepSize + 2
NEXT
Demo Program (FORNEXT.bs2)
' This example uses a FOR...NEXT loop to churn out a series of sequential squares
' (numbers 1, 2, 3, 4... raised to the second power) by using a variable to set the
' FOR...NEXT StepValue, and incrementing StepValue within the loop. Sir Isaac Newton
' is generally credited with the discovery of this technique.
'{$STAMP BS2}
Square
VAR
BYTE
StepSize
VAR
BYTE
loop.
StepSize = 1
Square = 1
FOR Square = 1 TO 250 STEP StepSize
DEBUG DEC ? Square
StepSize = StepSize + 2
NEXT
Page 122 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
' Counter for the loop.
' Each loop add 1.
' Show reps in debug window.
'STAMP directive (specifies a BS1)
' FOR/NEXT counter and series of squares.
' Step size, which will increase by 2 each
' Show squares up to 250.
' Display on screen.
' Add 2 to StepSize
' Loop til square > 250.
'STAMP directive (specifies a BS2)
' FOR/NEXT counter and series of squares.
' Step size, which will increase by 2 each
' Show squares up to 250.
' Display on screen.
' Add 2 to StepSize
' Loop til square > 250.
2
2
2
2
e
sx
p
1
2
2
2
2
e
p
sx
NOTE: This is written for the BS2
but can be used for the BS2e,
BS2sx and BS2p also. Locate the
proper source code file or modify
the STAMP directive before
downloading to the BS2e, BS2sx or
BS2p.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?