Factorial: Difference between revisions

Content added Content deleted
(Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag)
Line 8,598:
===Iterative===
Standard iterative solution using a <code>for</code> loop:
* <code>range(2, nnum, :incl)</code> creates an inclusive range (<code>2 <= i <= nnum</code>) for iteration
 
<syntaxhighlight lang="scala">
Line 8,613:
===Recursive===
Standard recursive solution using a pattern matching approach:
* <code>require num >= 0;</code> enforces argument preconditions
* <code>match</code> without arguments is a ''conditional match'', which works like <code>if/else</code> chains.
* Rhovas doesn't perform tail-call optimization yet, hence why this solution isn't tail recursive.