Have you ever heard someone say "to reiterate"? Do you know what they mean? To reiterate is to repeat something.
Sometimes Algorithms contain steps that are repeated numerous times. These repeated steps are called iterations or loops.
For example the steps involved in brushing your teeth could be written as:
When we talk about iterations in maths, we are talking about repeating something. If I say there have been 5 iterations of something, it means it has happened 5 times. The important thing is that each time the iteration happens it is building on the previous result.
Let's go through an example to make this clearer.
$4$4 times table:
I can write an algorithm for writing down the four times table like this:
If we did this I would get $0$0, $4$4, $8$8, $12$12, $16$16, $20$20 , $24$24, $28$28, $32$32, $36$36, $40$40, $44$44, $48$48. This is $12$12 iterations of add $4$4.
Another word that is often used to describe an iteration is a loop. If you loop through something then you are repeating it.
This is a really great way to make use of a computer - if I asked you to keep repeating the same task over and over again you would quickly get bored, right? Well a computer won't ever get bored.
Nadia follows an algorithm to eat her breakfast.
Does this algorithm contain a loop?
No
Yes
Which two steps form the loop? Write both steps on the same line, separated by a comma.
Follow the algorithm below.
Step | Instruction | Result |
---|---|---|
$1$1 | Start with the number $29$29 | $\editable{}$ |
$2$2 | Subtract $1$1 from this number | $\editable{}$ |
$3$3 | Repeat step $2$2 three more times | $\editable{}$ |
$\editable{}$ | ||
$\editable{}$ | ||
$4$4 | Double the number | $\editable{}$ |