School preview · Teacher-led courses are in preview · Registration is open · Payments and live video are awaiting connection
← Class 6 ICT

Class 6 · English Medium · Pearson Edexcel · ICT

Data, logic and algorithms

Trace a loop and explain a loop invariant.

Original Kidemy further-topic investigation. This optional lesson is shared by related upper pathways; select suitable depth with a teacher. It does not certify complete grade or board coverage.

Learn the idea

A loop invariant is a property preserved at a stated point in each iteration. It helps explain correctness beyond a few test cases. A termination argument explains why the loop ends. Tests can reveal errors but do not by themselves prove every input works.

Worked example

To sum1 to n: total=0; for k=1..n add k. After processing k, total equals1+...+k. The next addition preserves that relation, and the finite counter supplies termination.

  1. Define the initial state.
  2. Show preservation in one step.
  3. Explain termination and edge cases.

Your written practice

Show your working on paper and enter your answer here. If it does not match, compare the model and try again.

Show model answer and explanation

10

1+2+3+4.

Show model answer and explanation

7

One per integer1 through7.

Show model answer and explanation

6

Include0 as well as1..5.

Write in your own words. A guardian or teacher should review this response.

Show model answer and explanation

After each processed number, total is the sum of all numbers processed so far.

Name the point in the loop.

Write in your own words. A guardian or teacher should review this response.

Show model answer and explanation

Its condition could remain true indefinitely if progress toward stopping is not guaranteed.

Explain how a variable approaches a stopping condition.

Apply the idea

Write a paper trace and invariant for counting items meeting a condition.

Review with a guardian or teacher

Keep your work on paper or in a local file. This page does not upload it or automatically grade the project.

Teacher-led lessons, schedules and prices for this outline are upcoming. You can use any starter practice above now without booking.

Your next step

Solo practice works without an account. Sign in to save a practice record to your learner profile.

Keep practising

Exact lesson links and related activities are labelled separately. Return-to-course links retain your selected learning path.

Browse all games and books →