Functions and recursion: Difference between revisions
wikademia>Remi0o added cats |
|||
| Line 186: | Line 186: | ||
:*Since n=4, we take the <tt>else<tt> path. We return 4×<tt>factorial(n-1)<tt> | :*Since n=4, we take the <tt>else<tt> path. We return 4×<tt>factorial(n-1)<tt> | ||
:*<tt>factorial(3)<tt> is called | :*<tt>factorial(3)<tt> is called | ||
::*Since n= | ::*Since n=3, we take the <tt>else<tt> path. We return 3×<tt>factorial(n-1)<tt> | ||
::*<tt>factorial(2)<tt> is called | ::*<tt>factorial(2)<tt> is called | ||
:::*Since n= | :::*Since n=2, we take the <tt>else<tt> path. We return 2×<tt>factorial(n-1)<tt> | ||
:::*<tt>factorial(1)<tt> is called | :::*<tt>factorial(1)<tt> is called | ||
::::*Since n=1, we take the first path and finally return 1 to the previous function | ::::*Since n=1, we take the first path and finally return 1 to the previous function | ||