teach-ict.com logo

THE education site for computer science and ICT

3. Using iteration loops

The first step towards structured programming is to make sensible use of iteration loops. We have a complete section on loops here. Loops include the FOR, WHILE and REPEAT constructs.

Iteration loops allow a set of operations to be repeated more than once. Like this

               count ← 1
                      WHILE count < 11  
                          OUTPUT count
                          count ← count + 1
                      ENDWHILE

Looping saves re-writing the same code over and over again but just as importantly it helps you see the logic of the operation.

For example, just by looking at the code above, it is easy to see there are 10 repeats of outputting a variable called count. The unstructured alternative would be to write OUTPUT count ten times.

We have a python example of using single loops here.

We have a python example of using nested loops here.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Structured programming