dec()

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

Syntax:

method dec(var value: Value, number: Value := 1): Value;
Value dec(ref Value value, Value number = 1);
func dec(_ inout value: Value, _ number: Value = 1) -> Value
Value dec(__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 dec() can be called without marking the parameter as pass-by-reference.

var x := 5;
dec(x);     // x is now 4
dec(var x); // x is now 3
int x = 5;
dec(x);     // x is now 4
dec(ref x); // x is now 3
var x = 5
dec(x)      // x is now 4
dec(&x)     // x is now 3
int x = 5;
dec(x);     // x is now 4
dec(__ref x); // x is now 3

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

int x = 5;
dec(x); // x is now 4
x--;    // x is now 3
var x = 5
dec(x)  // x is now 4
x--     // x is now 3
int x = 5;
dec(x); // x is now 4
x--;    // x is now 3

See Also