I said everything could be done by iterative way but can not be done through recursive where my friend said the exact opposite way. Not sure which one is true.
You can design languages that have only iteration, such as Dijkstra's guarded command language extended with data types, or have only recursion, such as the lambda calculus, and each can code up the other as an interpreter. So there is a basic sense in which neither is more expressive than the other.<p>But there is a sense in which recursion is more expressive than iteration, in the sense of being a flexible local abstraction: in a language with tail recursion, iterative loops can be directly encoded by means of recursive calls. And indeed this is how iteration is expressed in the Scheme language. Trying to encode recursion in terms of iteration cannot be done so directly.
Depends exactly on what you mean by iterative and recursive functions.<p>Summing a list could be done by:<p>sum_iterative( list ) {
sum = 0
for( element in list ) {
sum += element
}
return sum
}<p>or<p>sum_recursive( list ) {
if( list.empty ) { return 0 } else {
return list.head + sum_recursive( list.tail )
}
}<p>So saying everything that can be done iteratively can't be done recursively is false, and also vice versa.