成人快手

Iteration in algorithms

An 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:

  • sequencing
  • selection
  • iteration

These building blocks help to describe solutions in a form ready for .

What is iteration?

An explanation of iteration, as used in algorithms and programming

Iteration in programming means repeating steps, or , over and over again. This is often called a 鈥榣oop鈥.

Iteration is the repetition of a sequence. In an arcade game, the sequence is Pop up a new rat, hit the rat increase score. This will continue to iterate as the game is being played.

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 has been met.

For example, a very simple algorithm for eating breakfast cereal might consist of these steps:

  • put cereal in bowl
  • add milk to cereal
  • spoon cereal and milk into mouth
  • repeat step 3 until all cereal and milk is eaten
  • rinse bowl and spoon

Why is iteration important?

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鈥檛 need to include lots of unnecessary steps.