Iteration

This lesson introduces to the basics of iteration.

What is iteration?

Iterative code is a block of code that runs in a loop. In other words, the same code is repeated over and over again. The idea is similar to that of recursion.

As you get comfortable with the recursion concept, you might not use iteration that frequently as you solve your problems, but there are definitely cases where you will find it valuable. This is also one of the easiest ways to ease yourself into recursion because we already understand how to iterate over arrays and lists. Recursion is basically taking the same concept forward but with some modifications.

For example,

  • Print a Linked List in reverse order
  • Factorial of a number
  • Fibonacci series
  • A problem where you expect to use a variable number of loops

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.