Logo

Programming-Idioms

History of Idiom 31 > diff from v77 to v78

Edit summary for version 78 by programming-idioms.org:
[Perl] Argument name i

Version 77

2022-05-23, 13:19:53

Version 78

2022-05-23, 13:20:25

Idiom #31 Recursive factorial (simple)

Create the recursive function f which returns the factorial of the non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create the recursive function f which returns the factorial of the non-negative integer i, calculated from f(i-1)

Variables
f,i
Variables
f,i
Code
sub f {
   my $n = shift;
   return $n<2 ? 1 : $n * f($n-1);
}
Code
sub f {
   my $i = shift;
   return $i<2 ? 1 : $i * f($i-1);
}