Definition & Types Of Iteration - Teach Computer Science
Maybe your like
KS3 Computer Science
11-14 Years Old
48 modules covering EVERY Computer Science topic needed for KS3 level.
View KS3 Resources →GCSE Computer Science
14-16 Years Old
45 modules covering EVERY Computer Science topic needed for GCSE level.
View GCSE Resources →A-Level Computer Science
16-18 Years Old
66 modules covering EVERY Computer Science topic needed for A-Level.
View A-Level Resources →Home / Programming / Iterations
GCSE Programming Resources (14-16 years)
- An editable PowerPoint lesson presentation
- Editable revision handouts
- A glossary which covers the key terminologies of the module
- Topic mindmaps for visualising the key concepts
- Printable flashcards to help students engage active recall and confidence-based repetition
- A quiz with accompanying answer key to test knowledge and understanding of the module
A-Level Problem solving and programming (16-18 years)
- An editable PowerPoint lesson presentation
- Editable revision handouts
- A glossary which covers the key terminologies of the module
- Topic mindmaps for visualising the key concepts
- Printable flashcards to help students engage active recall and confidence-based repetition
- A quiz with accompanying answer key to test knowledge and understanding of the module
Iteration is the term given to the repetition of a block of instructions (code) within a computer program for a number of instances or until status is encountered. When the first group of instructions is carried out again, it is called an iteration. When a cycle of instructions is carried out in a repeated manner, it is called a loop. It is the replication of a process in a computer program, commonly executed with the use of loops.
Iteration is essential as it lets a programmer streamline a design by declaring that definite steps will be repeated. It is also briefer since a number of irrelevant steps are removed. Steps that are part of the loop are indented. Indentation is used to show which steps are to be repeated. Many computer programs use iterations to execute specific tasks, resolve problems and provide solutions.
Types of Iteration
There are two types of iteration:
Count-controlled loops
– used for iterating steps a specific number of times. It is used when the number of iterations to take place is already known. It uses a counter to keep track of how many times the set of commands has been repeated.
Count-controlled loops are executed using FOR statements.
- for – specifies the starting point of the iteration
- range – indicates how many times the program will iterate
Count Controlled Loop Example
total = 0 for count in range (4): number = int (input (“Type in a number: “)) total = total + number print (“The total is: “) print (total)
A count controlled loop iteration exampleThe above program works as follows:
- The variable ‘count’ is used to keep track how may times the iteration happened.
- The ‘for’ statement is used to determine where the loop starts.
- The ‘range’ declaration signifies the number of instances the loop is to occur.
- The variable ‘count’ regulates the repetition.
- In every repetition, program consequently adds 1 to the value of ‘count’.
- The program continues to iterate if the value of ‘count’ is in the range declared in the loop. Once it gets to the end of the range, the repetition stops.
In the above example, the program repeats 4 times. To have a different number of repetitions, the value ’4’ would simply have to be changed to the number of times preferred.
Condition-controlled loops
– used for iterating steps continuously until a condition is met. It is used when the number of iterations to take place is unknown. The algorithm tests the condition to see if it is true. If true, the algorithm executes a command. If false, the algorithm goes back to step 1 and will continue to go back until the condition becomes true.
Condition-controlled loops are executed using WHILE statements.
Condition Controlled Loop Example
total = 0 answer = “yes” while answer = “yes”: number = int (input (“Type in a number: “)) total = total + number answer = input (“Any more numbers? yes/no “) print (“The total is: “) print (total)
Code exampleThe above program works as follows:
- The ‘while’ statement is used to indicate where the iteration starts.
- The condition ‘answer = “yes”’ is used to manage the iteration. It must be set to “yes” at the start so the code runs at least once.
- The program assesses the condition by checking if the variable ‘answer’ equals “yes”.
- If the condition is true, the program repeats.
- If the condition is false, the program progresses to the next step.
The program iterates as many times as is necessary and will keep iterating as long as the condition is met.There are instances where a condition-controlled loop loops forever. This is called an infinite loop. An infinite loop ensures that a program runs forever which can be used in controlling a traffic light and other similar scenarios.
Further Readings:
- Iteration
About this site
Teach Computer Science provides detailed and comprehensive teaching resources for the new 9-1 GCSE specification, KS3 & A-Level. Equally suitable for International teachers and students.
Over 5,000 teachers have signed up to use our materials in their classroom.
Search for:What do we provide?
In short: everything you need to teach GCSE, KS3 & A-Level Computer Science:
- Condensed revision notes
- Exam question booklets
- Mind maps
- Interactive quizzes
- PowerPoint presentations
- Flashcards
Exam boards
Our materials cover both UK and international exam board specifications:
- AQA
- CIE
- Edexcel
- OCR
- Eduqas
- WJEC
- National 5
Tag » What Is Iteration In Computer Science
-
What Is Iterative? - TechTarget
-
What Is Iteration? - Definition From Techopedia
-
Iteration - Computer Science Wiki
-
Iteration In Algorithms - KS3 Computer Science Revision - BBC
-
What Is Iteration In Programming? - AfterAcademy
-
Iteration - Wikipedia
-
FAQ: What Is An Iteration In Computer Science? (With Examples)
-
Iteration - Isaac Computer Science
-
Iteration - Computer Science GCSE GURU
-
What Is Iteration? - Quora
-
What Is An Iteration? - Computer Hope
-
Iteration Examples In Real Life And Computer Programming
-
7. Iteration — How To Think Like A Computer Scientist
-
The Building Blocks Of Algorithms - Khan Academy