💻 Computer Science · Topic 27 of 97

Iteration: Loops

Iteration repeats a block of code, using loops such as for and while.

▶ Interact

Play with the controls to see the idea in action.

Loading animation…

📘 Learn

Iteration repeats a block of code, using loops such as for and while.

  • For loops repeat a set number of times
  • While loops repeat until a condition changes
  • Avoid infinite loops

🧠 Quick quiz

Three questions. Score 2 or more to complete the topic.

What is Iteration: Loops?

Within Computer Science, which covers algorithms, programming, data, networks, hardware and safe, responsible use of technology, this topic explains Iteration: Loops. Computing topics explain how software, hardware and data work, with diagrams and models that show each step in order.

Check that you can explain Iteration: Loops in your own words and give one example from everyday life. If you can do that, you have understood the core idea.

Understanding Iteration: Loops helps you design, test and explain programs, websites and systems, from small projects to exam questions.

Iteration: Loops in detail

Iteration repeats a block of code. A FOR loop (count-controlled) repeats a set number of times, such as for i in range(5). A WHILE loop (condition-controlled) repeats as long as a condition is true, checking before each pass, and a REPEAT...UNTIL loop checks at the end, so it runs at least once.

Loops avoid repeating code, process lists, validate input and run games. An infinite loop never ends, caused by a condition that never becomes false, which is a common bug. Loops can be nested for tasks such as grids. Counters and accumulators are used to keep track of totals.

How the interactive helps you understand Iteration: Loops

Watch the cycle in the interactive. Use any sliders or buttons it offers to change the values and see how the cycle responds.

Before you change anything, predict the result. Then change one value at a time and check whether your prediction was right. This is a quick way to build a correct mental model of Iteration: Loops.

Real-life uses and examples

Common mistakes to avoid

Frequently asked questions about Iteration: Loops

What is Iteration: Loops?

Iteration repeats a block of code, using loops such as for and while.

What are the most important points about Iteration: Loops?

The main points are: For loops repeat a set number of times; While loops repeat until a condition changes; Avoid infinite loops.

Why is Iteration: Loops useful?

Understanding Iteration: Loops helps you design, test and explain programs, websites and systems, from small projects to exam questions.

How can I practise Iteration: Loops?

Open the interactive at the top of this page and change the controls one at a time. Predict the result before each change, then take the three-question quiz. A score of two or more marks the topic as complete on this device.

Which topics are related to Iteration: Loops?

Related topics in Computer Science include Functions and Procedures, Validation and Verification, Searching Algorithms.

← PreviousSelection: If StatementsNext →Arrays and Lists

Keep exploring Computer Science