aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/example.imp21
-rw-r--r--examples/factorial.imp9
2 files changed, 19 insertions, 11 deletions
diff --git a/examples/example.imp b/examples/example.imp
index a5bc5dd..de76b27 100644
--- a/examples/example.imp
+++ b/examples/example.imp
@@ -1,12 +1,11 @@
-procedure factorial(n;r) begin
- if n <= 0 then
- r := 1;
- else
- m := n - 1;
- factorial(m;r);
- r := r * n;
- end;
-end;
-
+f1 := 0;
+f2 := 1;
n := 5;
-factorial(n;r); \ No newline at end of file
+
+while n # 0 do
+ var tmp := f2 in
+ f2 := f1 + f2;
+ f1 := tmp;
+ end;
+ n := n - 1;
+end; \ No newline at end of file
diff --git a/examples/factorial.imp b/examples/factorial.imp
new file mode 100644
index 0000000..0ab74cd
--- /dev/null
+++ b/examples/factorial.imp
@@ -0,0 +1,9 @@
+procedure factorial(n;r) begin
+ if n <= 0 then
+ r := 1;
+ else
+ m := n - 1;
+ factorial(m;r);
+ r := r * n;
+ end;
+end; \ No newline at end of file