IF...THEN - BASIC Stamp Command Reference
Demo Program (IFTHEN.bas)
' The program below generates a series of 16-bit random numbers and tests each to
' determine whether they're evenly divisible by 3. If a number is evenly divisible
' by 3, then it is printed, otherwise, the program generates another random number.
' The program counts how many numbers it prints, and quits when this number reaches 10.
'{$STAMP BS1}
SYMBOL
Sample
=
SYMBOL
Samps
=
SYMBOL
Temp
=
Sample = 11500
Mul3:
RANDOM Sample
Temp = Sample // 3
IF Temp <> 0 THEN Mul3
DEBUG #Sample," is divisible by 3.", CR
Samps = Samps + 1
IF Samps = 10 THEN DONE
GOTO Mul3
Done:
DEBUG CR, "All done."
END
Demo Program (IFTHEN.bs2)
' The program below generates a series of 16-bit random numbers and tests each to
' determine whether they're evenly divisible by 3. If a number is evenly divisible
' by 3, then it is printed, otherwise, the program generates another random number.
' The program counts how many numbers it prints, and quits when this number reaches 10.
'{$STAMP BS2}
Sample
VAR
WORD
Samps
VAR
NIB
Mul3:
RANDOM Sample
IF NOT Sample // 3 = 0 THEN Mul3
DEBUG DEC Sample," is divisible by 3.",CR ' Print message.
Samps = Samps + 1
IF Samps = 10 THEN DONE
GOTO Mul3
Done:
DEBUG CR,"All done."
STOP
Page 154 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
'STAMP directive (specifies a BS1)
W0
' Random number to be tested.
B2
' Number of samples taken.
B3
' Temporary workspace
' Put a random number into sample.
' Not multiple of 3? Try again.
' Print message.
' Count multiples of 3.
' Quit with 10 samples.
'STAMP directive (specifies a BS2)
' Random number to be tested.
' Number of samples taken.
' Put a random number into sample.
' Not multiple of 3? Try again.
' Count multiples of 3.
' Quit with 10 samples.
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?