|
<< Index >> |
FutureBasic |
inc, dec & related addition/subtraction statements | statements | |
|
Syntax 1 | ||
( ) |
increments an integer variable by one | |
( ) |
decrements an integer variable by one | |
Syntax 2 | ||
SInt64 | long | word | byte } ( ) |
increments an integer variable indirectly by one | |
SInt64 | long | word | byte } ( ) |
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 | |
Syntax 5 (pre/post increment/decrement) | ||
integerVar = ++otherIntegerVar |
increment otherIntegerVar before assigning to integerVar | |
integerVar = --otherIntegerVar |
decrement otherIntegerVar before assigning to integerVar | |
integerVar = otherIntegerVar++ |
assign otherIntegerVar to integerVar then increment otherIntegerVar | |
integerVar = otherIntegerVar-- |
assign otherIntegerVar to integerVar then decrement otherIntegerVar |
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. (
)
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.
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 adds)
Incrementing a variable's integer value directly with syntax 1:
|
declare variable & initialize to 37 | |
(myInt) |
myInt's value after the increment is now 38 |
Incrementing a variable's integer value via a pointer with syntax 2:
|
declare variable and initialize | |
|
declare a pointer to a long and initialize to var's address | |
(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:
PassPtrToFunc( aLong
^long )
long (aLong)
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: | ||
|
declare variable and initialize | |
myInt++ |
value after the increment is now 38 | |
Adding to a variable's integer value with syntax 4: | ||
|
declare variable and initialize | |
myInt += 4 |
after adding 4 the value is 41 |
Equivalents for Syntax 2
(address&) |
...is equivalent to: | address&, (address&) + 1 |
(address&) |
...is equivalent to: | address&, (address&) + 1 |
Notes
This page consolidates all help for these: inc, dec, ++/--, -+/-=
and related commands.