|
Iteration allows the execution of a sequential set of statements repetitively using conditional loops. In recursion a statement in the function’s body calls the function itself. In Iteration there are loops with a control variable that need to be initialized, incremented or decremented and a conditional control statement that continuously gets checked for the termination of execution. A recursive function must comprise of at least one base case i.e. a condition for termination of execution.
|
![]() Intrigued? learn more..
|
In iteration the value of the control variable continuously approaches the value in the conditional statement.
The recursive function keeps on converging to the defined base case as it continuously calls itself. In iteration a control variable stores the value, which is then updated, monitored, and compared with the conditional statement. In recursion "stack" memory is used to store the current state of the function. In iteration Infinite loops keep utilizing CPU cycles until we stop their execution manually. In recursion if there is no base case defined, recursion causes a stack overflow error. |
Science
|
Technology
|
Engineering
|
Mathematics
|
Empowerment
|