INC

INC Variable

Increments a variable. Variable can be any target of an assignment, but must be numeric.


Example

' First example
X = 7
INC X
PRINT X

8

' Second example
DIM A[3, 3] AS FLOAT

X = 2
Y = 1

A[X, Y] = PI
INC A[X, Y]
PRINT A[X, Y]

4.14159265359

A longer example in the terminal modus of Gambas Be careful x = INC x does not work. Of course you can use the following instead: x = x + 1

STATIC PUBLIC SUB Main()
DIM x AS Float
DIM y AS Float
DIM pos AS Integer
DIM neg AS Integer
DIM nul AS Integer
pos = 0
neg = 0
nul = 0
FOR x = 1 TO 100
 y = Rnd(-5, 5)
 SELECT CASE Sgn(y) 
  CASE 0 
   INC nul 
   'the same as nul = nul + 1
  CASE 1 
   INC pos
  CASE -1 
   INC neg 
 END SELECT 
NEXT 
PRINT nul,pos,neg
END


See Also

DEC, MOD, ArithmeticOperators


Previous: If / IIf Next: INPUT