An algorithm is a plan, a set of step-by-step instructions to solve a problem. There are three basic building blocks (constructs) to use when designing algorithms:
These building blocks help to describe solutions in a form ready for programming.
Iteration in programming means repeating steps, or instructions, over and over again. This is often called a ‘loop’.
Algorithms consist of instructions 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:
Iteration allows algorithms to be simplified by stating that certain steps will repeat until told otherwise. This makes designing algorithms quicker and simpler because they don’t need to include lots of unnecessary steps.