Positron Compiler Documentation

Dec

Positron16 · Revision 1.1.3.5 · PDF page 331

Dec Variable {, DecrementVariable}

Decrement a variable i.e. Var1 = Var1 - 1, or decrement a variable by the value held in parameter 2. i.e. Var1 = Var1 – Var2

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.

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
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.

View original PDF page 331Open page in PDFOriginal PDF page 331