Advertisement
cwchen

[Perl 6] Recursion demo: factorial

Nov 15th, 2017
3,442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.17 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment
Advertisement