Logo

Programming-Idioms

History of Idiom 31 > diff from v73 to v74

Edit summary for version 74 by AlfRichter:
[Kotlin] Add Doc

Version 73

2022-02-01, 23:40:02

Version 74

2022-02-01, 23:40:48

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
fun f(i: Int) = if (i == 0) 1 else i * f(i - 1)
Code
fun f(i: Int) = if (i == 0) 1 else i * f(i - 1)
Doc URL
https://kotlinlang.org/docs/functions.html#tail-recursive-functions