progs/fib.while
changeset 207 f824e1331fc6
parent 182 9ce2414e470e
child 208 bd5a8a6b3871
--- a/progs/fib.while	Tue Nov 26 22:45:06 2013 +0000
+++ b/progs/fib.while	Wed Nov 27 08:49:51 2013 +0000
@@ -1,16 +1,17 @@
-/* Fibonnacci numbers implemented in 
-   the WHILE language */
-   
-write "Input a number ";
+/* Fibonacci Program
+   input: n
+*/
+//write "Fib";
 read n;
-x := 0;   // start values
-y := 1;
+//n := 19;
+minus1 := 0;
+minus2 := 1;
 while n > 0 do {
-  temp := y;
-  y := x + y;
-  x := temp;
-  n := n - 1  // decrement counter
+       temp := minus2;
+       minus2 := minus1 + minus2;
+       minus1 := temp;
+       n := n - 1
 };
-write "Result ";
-write y
+write "Result";
+write minus2