FutureBasic Logo

<<    Index    >> FutureBasic

inc, dec & related addition/subtraction statements   statements



Syntax 1
inc (integerVariable) increments an integer variable by one
dec (integerVariable) decrements an integer variable by one
Syntax 2
inc { SInt64 | long | word | byte } (address) increments an integer variable indirectly by one
dec { SInt64 | long | word | byte } (address) decrements an integer variable indirectly by one
Syntax 3
integerVariable++ suffixed ++ increments the integer variable by one
integerVariable-- suffixed -- decrements the integer variable by one
Syntax 4
myIntVar += integerValueToAdd equivalent to: myIntVar = myIntVar + integerValueToAdd
myIntVar -= valueToSubtract equivalent to: myIntVar = myIntVar - valueToSubtract

Description (mentions only incrementing; decrementing is essentially the same except it subtracts instead of adding)
Syntax 1 increments a numeric value stored in an integer variable by accessing it directly.
e.g. inc (myVar) myVar is a local or global SInt64, long, word or byte integer variable.

Syntax 2 also increments an integer variable but accesses it indirectly through a pointer ( i.e. address )
A required sub-keyword (SInt64, long, word or byte) specifies the type of the numeric variable.
Useful when a variable is passed by address to a function.

Syntax 3 increments the variable's numeric content in the same manner as syntax 1.

Syntax 4 is a shorthand version of: myIntVar = myIntVar + integerValueToAdd

Examples( incrementing only shown; decrementing is essentially the same except it subtracts instead of adding )

Incrementing a variable's integer value directly with syntax 1:
dim as long myInt = 37 declare variable & initialize to 37
inc (myInt) myInt's value after the increment is now 38

Incrementing a variable's integer value via a pointer with syntax 2:
dim as long myInt = 37 declare variable and initialize
dim as ^long myIntPtr = @myInt declare a pointer to a long and initialize to var's address
inc long (myIntPtr) since myIntPtr points to myInt, this indirectly increments myInt by one

Incrementing a variable's integer value via a pointer from a called function with syntax 2:

local fn PassPtrToFunc( aLong as ^long )
inc long (aLong)
end fn

fn PassPtrToFunc( @myInt ) if myInt started with a value of 37, after the call it would be 38
Incrementing a variable's integer value directly with syntax 3:
dim as long myInt = 37 declare variable and initialize
myInt++ value after the increment is now 38
Adding to a variable's integer value with syntax 4:
dim as long myInt = 37 declare variable and initialize
myInt += 4 after adding 4 the value is 41

Equivalents for Syntax 2
inc long(address&) ...is equivalent to: poke long address&, peek long (address&) + 1
inc word (address&) ...is equivalent to: poke word address&, peek word (address&) + 1

Notes
This page consolidates all help for these: inc, dec, ++/--, -+/-= and related commands.