Positron Compiler Documentation

Dec

Positron8 · Revision 4.0.6.5 · PDF page 324

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 = 18F25K20             ' Select the device to use
Declare Xtal = 16             ' Set its frequency
Declare Hserial_Baud = 9600   ' Set the Baud rate for the HRsoutLn command

Dim MyByte as Byte = 11       ' Create a variable and give it an initial value

Repeat                         ' Create a loop
  Dec MyByte                  ' Decrement the variable MyByte
  HRsoutLn Dec MyByte        ' Transmit the decimal value serially
  DelayMs 200                ' A delay to see what’s happening
Until MyByte = 0              ' Loop until the variable reaches 0

The above example shows the equivalent to the For-Next loop: -

For MyByte = 10 to 0 Step -1
Next
Device = 18F25K20             ' Select the device to use
Declare Xtal = 16             ' Set its frequency
Declare Hserial_Baud = 9600   ' Set the Baud rate for the HRsoutLn command

Dim MyWord as Word = 110       ' Create a variable and give it an initial value

Repeat                         ' Create a loop
  Print 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 324Open page in PDFOriginal PDF page 324