old-trainOS/trainscript/file01.ts

28 lines
418 B
TypeScript
Raw Normal View History

VAR res : INT;
PUB main(x : INT) c : INT
2015-08-10 14:37:16 +00:00
BEGIN
2015-08-12 10:15:47 +00:00
# factorial(10) res;
fibonacci(7) res;
END
PUB factorial(number : INT) result : INT
BEGIN
IF number > 1 THEN
number * factorial(number - 1) result;
2015-08-12 10:15:47 +00:00
ELSE
1 result;
END
# Recursive test
PUB fibonacci(n : INT) f : INT
BEGIN
IF n = 0 THEN
0 f;
ELSEIF n = 1 THEN
1 f;
ELSE
fibonacci(n - 1) + fibonacci(n - 2) f;
2015-08-10 14:37:16 +00:00
END