Inc
Positron16 · Revision 1.1.3.5 · PDF page 339
Syntax
Inc Variable {, IncrementVariable}
Overview
Increment a variable i.e. Variable = Variable + 1, or increment a variable by the value held in parameter 2. i.e. Variable = Variable + IncrementVariable
Parameters
Variable is a user defined variable that will be incremented IncrementVariable is an optional variable or expression or constant that will be added to the first variable.
Example1
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyDword as Dword = 1
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
Repeat
HrsoutLn Dec MyDword
DelayMs 200
Inc MyDword
Until MyDword > 10000
The above example shows the equivalent to the For-Next loop: -
For MyDword = 1 to 10000 : Next
However, the Repeat-Until version, although it looks more complex, is much more efficient in both code size and speed of operation.
Example 2
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 16
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyDword as Dword = 1
Repeat ' Create a loop
HRsoutLn Dec MyDword ' Transmit the ASCII value to a serial terminal
DelayMs 200 ' A delay so the value can be seen changing
Inc MyDword, 10 ' Increment the variable MyDword by 10
Until MyDword > 1000 ' Loop until the variable reaches 1000 or over
See also : Dec.
