INC / DEC

Statement

Syntax

Adds 1, or an amount, to a variable (INC), or subtracts it (DEC).

INC <target>[, <amount>]
DEC <target>[, <amount>]

Also written : INC, DEC

Parts

<target>A variable, an array cell in square brackets (a[i]), a field (p.x), or a mix (ps[i].x). It must already exist.
<amount>Optional. What is added or subtracted; default 1. Any expression, decimals included.

Good to know

  • On a typed variable, the result is converted like any write to that type: an uint8 at 255 goes to 0.
  • INC a(1) with round brackets compiles into a program that does not start; so do INC ps(1).x, INC l() and INC m("k"). Write INC a[1], INC ps[1].x, l() = l() + 1, m("k") += 1.
  • A target never assigned before stops the program: INC n alone gives n is not defined. Give it a value first.
  • Under OPTION EXPLICIT, the target must be declared first.

Example

n = 5INC nINC n, 10DEC n, 3Console(Str(n))   ' 13DIM a(2)INC a[1], 4Console(Str(a[1]))   ' 4b AS uint8 = 255INC bConsole(Str(b))   ' 0
In the manual : Arrays, lists and maps