Year 11 Exam  >  Year 11 Notes  >  Computer for GCSE/IGCSE  >  Iteration

Iteration | Computer for GCSE/IGCSE - Year 11 PDF Download

What is iteration? 

Iteration, an essential programming concept, involves repeating a set of instructions until a certain condition is fulfilled. It's utilized to automate repetitive tasks.
There are three main types of iteration: 

  • Count-controlled loops
  • Precondition loops
  • Postcondition loops

Count-controlled Loops

  • Count-controlled loops are utilized when the number of iterations is predetermined beforehand. 
  • They are also referred to as definite loops.
  • These loops operate based on a counter variable that is either increased or decreased after each iteration, and the loop continues until the counter reaches a specified value.

Example in Pseudocode:
count ← 1
FOR i <= 10
OUTPUT count
NEXT i

Example in Python:
for count in range(1, 11):
print(count)

Example in Java:
for(int count=1; count<=10; count++){
System.out.println(count);
}

Example in Visual Basic:
For count = 1 To 10
Console.WriteLine(count)
Next count

Pre-condition Loops

  • A precondition loop is employed when the quantity of iterations isn't predetermined but relies on a condition being true.
  • It's alternatively referred to as an indefinite loop.
  • This loop persists in execution as long as the condition remains true, ceasing when the condition turns false.

Example in Pseudocode:
INPUT temperature
WHILE temperature > 37 DO
OUTPUT "Patient has a fever"
INPUT temperature
END WHILE

Example in Python:
temperature = float(input("Enter temperature: "))
while temperature > 37:
print("Patient has a fever")
temperature = float(input("Enter temperature: "))

Example in Java:
Scanner input = new Scanner(System.in);
float temperature = input.nextFloat();
while (temperature > 37) {
System.out.println("Patient has a fever");
temperature = input.nextFloat();
}

Example in Visual Basic:
temperature = InputBox("Enter temperature")
Do While temperature > 37
Console.WriteLine( "Patient has a fever")
Console.WriteLine("Enter temperature")
temperature=Console.ReadLine()
Loop

Postcondition Loops

  • Postcondition loops are utilized when a loop needs to run at least once, irrespective of the initial condition being false.
  • The condition is assessed at the conclusion of the loop's execution.

Example in Pseudocode:
REPEAT
INPUT guess
UNTIL guess = 42

Example in Python:
Postcondition loops don’t exist in Python and would need to be restructured to a precondition loop

Example in Java:
Scanner input = new Scanner(System.in);
int guess = 0;
do {
System.out.print("Enter guess: ");
guess = input.nextInt();
} while (guess != 42);

Example in Visual Basic:
Do
Console.WriteLine("Enter guess")
guess = Console.ReadLine()
Loop Until guess = 42

The document Iteration | Computer for GCSE/IGCSE - Year 11 is a part of the Year 11 Course Computer for GCSE/IGCSE.
All you need of Year 11 at this link: Year 11
92 docs|30 tests

Top Courses for Year 11

FAQs on Iteration - Computer for GCSE/IGCSE - Year 11

1. What is iteration in programming?
Ans. Iteration in programming refers to the process of repeating a set of instructions or a block of code multiple times. It is often achieved using loops such as for loops, while loops, or do-while loops.
2. How does iteration help in simplifying code?
Ans. Iteration allows programmers to avoid writing repetitive code by executing the same block of code multiple times with slight variations, making the code more concise and easier to maintain.
3. What are the common types of iteration structures used in programming?
Ans. The common types of iteration structures used in programming are for loops, while loops, and do-while loops. Each type of loop has its own specific use cases and syntax.
4. Can iteration be used to iterate over data structures like arrays or lists?
Ans. Yes, iteration is commonly used to traverse and manipulate data structures like arrays, lists, or maps. Programmers can access each element in the data structure sequentially using loops for various operations.
5. How does iteration contribute to the efficiency of a program?
Ans. By using iteration, programmers can perform repetitive tasks efficiently without duplicating code, resulting in cleaner and more maintainable code. Additionally, iteration allows for better control over the flow of the program and can significantly reduce the execution time.
92 docs|30 tests
Download as PDF
Explore Courses for Year 11 exam

Top Courses for Year 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

shortcuts and tricks

,

Previous Year Questions with Solutions

,

Exam

,

Objective type Questions

,

Important questions

,

MCQs

,

Sample Paper

,

Summary

,

Free

,

Iteration | Computer for GCSE/IGCSE - Year 11

,

Semester Notes

,

mock tests for examination

,

study material

,

Iteration | Computer for GCSE/IGCSE - Year 11

,

pdf

,

Viva Questions

,

past year papers

,

practice quizzes

,

Iteration | Computer for GCSE/IGCSE - Year 11

,

ppt

,

video lectures

,

Extra Questions

;