Difference between Recursion and Iteration | -- -- - Recursion -- -- - method to find factorial of given number ; recursion call ; -- -- - Iteration -- -- - Method to find the factorial of a given number ; using iteration ; Driver method
function factorialUsingRecursion ( n ) { if ( n == 0 ) return 1 ; return n * factorialUsingRecursion ( n - 1 ) ; } function factorialUsingIteration ( n ) { var res = 1 , i ; for ( i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } var num = 5 ; document . write ( " " + num + " " + factorialUsingRecursion ( 5 ) + " " ) ; document . write ( " " + num + " " + factorialUsingIteration ( 5 ) ) ;