inc
Increments a number.
Syntax
-
inc(x[, n])
-
x
is a variable containing a number -
n
is an integer
-
Description
If x
is a variable that is currently containing a number (which includes integers, rational numbers, real numbers, and complex numbers), then inc(x, n)
increases the value of x
by n
; hence, its new value becomes x + n
. This value is also returned by the inc
function. If omitted, n
will be set to 1
.
Technically, x
must be an lvalue of type number. It can be a variable or a subscript or member of an object container variable.
Examples
f ≔ n ↦ if(even(n), n/2, 3⋅n + 1);
st ≔ n ↦ (c ≔ 0; k ≔ n; while(k ≠ 1, (k ≔ f(k); inc(c))); c);
WordWrap(join(SequenceList(100) @ st))
0, 1, 7, 2, 5, 8, 16, 3, 19, 6, 14, 9, 9, 17, 17, 4, 12, 20, 20, 7, 7, 15, 15, 10, 23, 10, 111, 18, 18, 18, 106, 5, 26, 13, 13, 21, 21, 21, 34, 8, 109, 8, 29, 16, 16, 16, 104, 11, 24, 24, 24, 11, 11, 112, 112, 19, 32, 19, 32, 19, 19, 107, 107, 6, 27, 27, 27, 14, 14, 14, 102, 22, 115, 22, 14, 22, 22, 35, 35, 9, 22, 110, 110, 9, 9, 30, 30, 17, 30, 17, 92, 17, 17, 105, 105, 12, 118, 25, 25, 25
c ≔ ToList(ZeroVector(10)); for(i, 1, 1000000, inc(c[1 + RandomInt(10)])); c
100055 100137 100092 99774 100109 100506 99629 100282 99376 100040