BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – FOR...NEXT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 197
Demo Program (FOR-NEXT.bs2)
' FOR-NEXT.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}
' {$PBASIC 2.5}
square VAR Byte ' FOR/NEXT counter
stepSize VAR Byte ' step size increases by 2 each loop
Setup:
stepSize = 1
square = 1
Main:
FOR square = 1 TO 250 STEP stepSize ' show squares up to 250
DEBUG DEC ? square ' display on screen
stepSize = stepSize + 2 ' add 2 to stepSize
NEXT ' loop until square > 250
END
All
2
NOTE: This example program can be
used with all BS2 models by changing
the $STAMP directive accordingly.