5: BASIC Stamp Command Reference – FOR…NEXT
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 119
Stamps do this automatically when the StartValue is greater than the
EndValue. Examples of both are shown below:
SYMBOL Reps = B0 ' Counter for the FOR/NEXT loop.
FOR Reps = 3 TO 1 STEP -1 ' Repeat with Reps = 3, 2, 1.
DEBUG #Reps, CR ' Each repetition, put the number of the
NEXT ' repetition on the screen.
-- or --
Reps VAR NIB ' Counter for the FOR/NEXT loop.
FOR Reps = 3 TO 1 ' Repeat with Reps = 3, 2, 1.
DEBUG DEC Reps, CR ' Each repetition, put the number of the
NEXT ' repetition on the screen.
Note that the code for the BS2, BS2e, BS2sx and BS2p did not use the
optional STEP argument. This is because we wanted to decrement by
positive 1 anyway (the default unit) and the BASIC Stamp realizes it needs
to decrement because the StartValue is greater than the EndValue. A
negative StepValue on the BS2, BS2e, BS2sx and BS2p would be treated as
its positive, two's compliment counterpart. For example, –1 in two’s
complement is 65535. So the following code executes only once:
Reps VAR NIB ' Counter for the FOR/NEXT loop.
FOR Reps = 3 TO 1 STEP -1 ' This will try to decrement 3 by 65535.
DEBUG DEC Reps, CR ' Each repetition, put the number of the
NEXT ' repetition on the screen.
The above code would run through the loop once with Reps set to 3. The
second time around, it would decrement Reps by 65535 (-1 is 65535 in
two's compliment) effectively making the number –65532 (4 in two's
compliment) which is outside the range of the loop.
All the arguments in the FOR…NEXT command can be constants,
variables or expressions (on the BS2, BS2e, BS2sx and BS2p). This leads to
some interesting uses. For example, if you make the StartValue and
EndValue a variable, and change their values within the loop, you'll change
the behavior of the loop itself. Try the following:
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
U
SING VARIABLES AS ARGUMENTS
.
Содержание 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...