tagged release 0.6.4
[parrot.git] / languages / jako / examples / fact.jako
blobeb77f579dea348eac9d0c15a2b846c519699bf6a
2 # fact.jako
4 # Some simple code to print some factorials
6 # Based on fact.pasm originally be Leon Brocard <acme@astray.com> 2001-09-14.
8 # Copyright (C) 2001-2005, The Perl Foundation.
9 # This program is free software. It is subject to the same
10 # license as the Parrot interpreter.
12 # $Id$
15 use sys;
17 const int N = 15;
21 # fact()
24 sub int fact(int n) {
25   var int i =  0;
26   var int f =  1;
28   while(i <= n) {
29     i++;
30     f *= i;
31   }
33   return f;
38 # MAIN PROGRAM:
41 var int f;
43 sys::print("Algorithm F1 (The factorial function)\n");
44 sys::print("    Calculating fact($N) = ...\n");
46 f = fact(N);
48 sys::print("    ... = $f\n");