Logo

Programming-Idioms

History of Idiom 31 > diff from v74 to v75

Edit summary for version 75 by AlfRichter:
[Kotlin] Add Demo

Version 74

2022-02-01, 23:40:48

Version 75

2022-02-01, 23:42:12

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
Doc URL
https://kotlinlang.org/docs/functions.html#tail-recursive-functions
Demo URL
https://pl.kotl.in/iIgWol-gn