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.
Содержание BASIC Stamp 1
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...