Programming-Idioms

History of Idiom 31 > diff from v49 to v50

Edit summary for version 50 :
[PHP] There's hardly any need for an else if we have 2 returns.

Version 49

2019-09-26, 14:36:02

Version 50

2019-09-26, 14:44:00

Idiom #31 Recursive factorial (simple)

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

Idiom #31 Recursive factorial (simple)

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

Code
function f($i) {
	if($i == 0) {
		return 1;
	}
	else {
		return ($i * f($i-1));
	}
}
Code
function f($i) {
	if($i == 0) {
		return 1;
	}

	return ($i * f($i-1));
}