IF…THEN - BASIC Stamp Command Reference
Page 154
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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} 'STAMP directive (specifies a BS1)
SYMBOL Sample = W0 ' Random number to be tested.
SYMBOL Samps = B2 ' Number of samples taken.
SYMBOL Temp = B3 ' Temporary workspace
Sample = 11500
Mul3:
RANDOM Sample ' Put a random number into sample.
Temp = Sample // 3
IF Temp <> 0 THEN Mul3 ' Not multiple of 3? Try again.
DEBUG #Sample," is divisible by 3.", CR ' Print message.
Samps = Samps + 1 ' Count multiples of 3.
IF Samps = 10 THEN DONE ' Quit with 10 samples.
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} 'STAMP directive (specifies a BS2)
Sample VAR WORD ' Random number to be tested.
Samps VAR NIB ' Number of samples taken.
Mul3:
RANDOM Sample ' Put a random number into sample.
IF NOT Sample // 3 = 0 THEN Mul3 ' Not multiple of 3? Try again.
DEBUG DEC Sample," is divisible by 3.",CR ' Print message.
Samps = Samps + 1 ' Count multiples of 3.
IF Samps = 10 THEN DONE ' Quit with 10 samples.
GOTO Mul3
Done:
DEBUG CR,"All done."
STOP
2
e
2
sx
2
p
2
1
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.
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...