Skip to main content

#mastery22 When to use what type of repetition in a program

1 min read

In program i think it's better to make iterative solutions, i'll show you why:

Recursive solution:

The difference is that when using a recursion it takes alot of time to print as you can see in the picture, iterative solution printed the answer when recursive solution is still calculating the fibonacci of 100.

It is also convenient to use recursion because an infinite loop occurs with iteration if the loop test never becomes false.

The difference is that iteration ends terminates when the loop condition falls whereas recursion terminates when a base case is recognized.

Here are some of the differences of both:

Gilberto Rogel García