Algorithms are used to help design programs that perform particular tasks.
Algorithms consist of steps that are carried out (performed) one after another. Sometimes an algorithm needs to repeat certain steps until told to stop or until a particular condition has been met.
For example, a very simple algorithm for eating breakfast cereal might consist of these steps:
The algorithm will repeat steps 3 and 4 until all the cereal and milk has been eaten.
Iteration allows us to simplify our algorithm by stating that we will repeat certain steps until told otherwise.
This makes designing algorithms quicker and simpler because they don’t have to include lots of unnecessary steps.
Once an algorithm has been designed and perfected, it must be translated – or programmed – into code that a computer can read.
We create programs to implement algorithms. Algorithms consist of steps. Programs consist of statements. A statement is a single instruction - in other words, a single step.
Iteration is implemented in programming using FOR and WHILE statements.
In programming, iteration is often referred to as ‘looping’, because when a program iterates it ‘loops’ to an earlier step.