User Manual

MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
160
FOR...NEXT
Syntax
for countVal = startVal to nishVal {step increment}
...code...
next
CountVal - a variable used to store the current count.
StartVal - the starting value to count from.
FinishVal - a value to count up or down to.
Increment - the value to increment the variable by through each loop.
Description
Repeats a block of instructions and increments a variable counter with a value specied each
time through the loop. The FOR...NEXT loop will exit when the count value is no longer between
start and nish. When no step increment is dened the default increment value is 1. If the
nishVal is modied by the instructions in the FOR...NEXT block the loop can be forced to
exit early. You can safely jump out of a FOR...NEXT loop.
Example
The example below will send the results to the USB port. It will count up from 0 to 9 then exit.
value var long
main
for value = 0 to 9
pause 1000
puts 0,["Value=",dec value,13]
next
end
The example below will print the results to a terminal window at 9600 baud. It will count down
from 9 to 0 then exit.
value var long
main
for value = 9 to 0
pause 1000
puts 0,["Value=",dec value,13]
next
end
The example below will print the results to a terminal window at 9600 baud. It will count up from
0 to 54 using 5 as the increment value then exit.
value var long
main
for value = 0 to 54 step 5
pause 1000
puts 0,["Value=",dec value,13]
next
end