Dec
Positron16 · Revision 1.1.3.5 · PDF page 331
Syntax
Dec Variable {, DecrementVariable}
Overview
Decrement a variable i.e. Var1 = Var1 - 1, or decrement a variable by the value held in parameter 2. i.e. Var1 = Var1 – Var2
Parameters
Variable is a user defined variable that will be decremented. DecrementVariable is an optional variable or expression or constant that will be subtracted from 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 MyWord as Word = 11
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
Do
Dec MyWord
HrsoutLn Dec MyWord
DelayMs 200
Loop Until MyWord = 0
The above example shows the equivalent to the For-Next loop: -
For MyWord = 10 to 0 Step -1
Next
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 MyWord as Word = 110 ' Create a variable and give it an initial value
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
Repeat ' Create a loop
HRsoutLn Dec MyWord ' Transmit the ASCII value to a serial terminal
DelayMs 200 ' A delay so the value can be seen changing
Dec MyWord, 10 ' Decrement the variable MyWord by 10
Until MyWord = 0 ' Loop until the variable reaches 0
See also : Inc.
