成人快手

Iteration

An is a plan, a set of step-by-step designed to solve a problem. There are three basic building blocks (constructs) to use when designing algorithms:

Algorithms are used to help design that perform particular tasks.

What is iteration?

An explanation of iteration, as used in algorithms and programming

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

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.

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

  1. put cereal in bowl
  2. add milk to cereal
  3. spoon cereal and milk into mouth
  4. repeat step 3 until all cereal and milk is eaten
  5. rinse bowl and spoon

The algorithm will repeat steps 3 and 4 until all the cereal and milk has been eaten.

Why is iteration important?

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

Iteration in programming

Once an algorithm has been designed and perfected, it must be translated 鈥 or 鈥 into code that a computer can read.

We create programs to 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 鈥榣ooping鈥, because when a program iterates it 鈥榣oops鈥 to an earlier step.