Iteration - Lakelands Computing

Title
Go to content
Iteration
Iteration is the technical word for loops. Programs often need to repeat bits of code over and over, either to be more efficient or to check if some condition has been met.There are two types of loops Count controlled loops and Condition controlled.
Count controlled loops
These simply say repeat this section of code this many times.  

They can be made a little bit more sophisticated than do this 10 times, for example count how many people are in the list of addresses, adding 1 to the number of customers each time.

That idea can be taken further too, for example count how many people are in the list of addresses whose town is "Ellesmere" adding 1 to the number of local customers each time.

For loops in Python are an example of a count controlled loop, as is repeat n times in scratch.
Condition Contolled Loops
These work on the idea of repeat until this condition is met.  They are often called while loops (as that is the word a nunber of languages use)

They are used with things like health in games - repeat until health is less than 1 then end.. , that can be wrote the other way round too - while health is more than 1 - repeat the following . The code to be continued could be to display the background, or keep the character moving - keep refreshing the display . A lot of game play is written in condition controlled loops

They are also used as a check  for example  while passwordCheck not = "passed"...deny access..
All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content