Advertisement
cwchen

[Perl 6] Recursion demo: factorial

Nov 15th, 2017
1,256
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";
Advertisement
RAW Paste Data Copied
Advertisement