daily pastebin goal
18%
SHARE
TWEET

[Perl 6] Recursion demo: factorial

cwchen Nov 15th, 2017 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub fac(Int $n where $n >= 0) returns Int {
  2.     if $n == 0 or $n == 1 {
  3.         return 1;
  4.     }
  5.    
  6.     $n * fac($n - 1);
  7. }
  8.  
  9. fac(5) == 120 or die "Wrong value";
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top