inc()

The inc() system function will increment a named variable, either by one (1) or by an optionally passed second value.

Syntax:

method inc(var value: Value, number: Value := 1): Value;
Value inc(ref Value value, Value number = 1);
func inc(_ inout value: Value, _ number: Value = 1) -> Value
Value inc(__ref Value value, Value number = 1);

The resulting type is equivalent to the passed value (referred to as Value above), and can be any Integer, Floating Point or Char type.

Even though the first parameter will be modified, for legacy and compatibility reasons, inc() and inc() can be called without marking the parameter as pass-by-reference.

var x := 5;
inc(x);     // x is now 6
inc(var x); // x is now 7
int x = 5;
inc(x);     // x is now 6
inc(ref x); // x is now 7
var x = 5
inc(x)      // x is now 6
inc(&x)     // x is now 7
int x = 5;
inc(x);     // x is now 6
inc(__ref x); // x is now 7

For C#, Swift and Java, calling inc() with a single parameter is comparable to using the ++ prefix or postfix operator.

int x = 5;
inc(x); // x is now 6
x++;    // x is now 7
var x = 5
inc(x)  // x is now 6
x++     // x is now 7
int x = 5;
inc(x); // x is now 6
x++;    // x is now 7

Operator Overloading

Custom types can add support for inc() (and dec()) by implementing the "Increment" operator using each language's support for operator overloading (e.g. using the operator keyword in Oxygene).

Custom implementations will only support the version of inc() with a single parameter (i.e. that increments by the equivalent of "1", comparable to the ++ prefix operator in C#, Swift, Java and Go.

Increment operator implementations should adjust the incoming var/ref parameter, as well as return its new value as result.

See Also