HelioLearnSkills for every stage

GRADE 12 · COMPUTATIONAL THINKING · ABOUT 60 MINUTES

Review an algorithm with an invariant

Use a maintained property to explain a loop.

Understand the idea

A loop invariant is a property that remains true at a defined point in every iteration. State initialisation, maintenance and what termination implies.

WORKED EXAMPLE

For summing [2,4,6], after k items total equals the sum of the first k items. At k=0 total=0; at k=1 total=2; k=2 total=6; k=3 total=12.

Watch it step by step

Step 1 of 4
TRACE THE STATE · READ THE EXPLANATION BELOWStep 10Step 2…Step 3…Step 4…Each state follows the specific rule in this workedexample.

Initialise

At k=0, total=0: no items have been processed.

Choose Play to advance steps automatically.

Read or choose any step
  1. Initialise

    At k=0, total=0: no items have been processed.

  2. Maintain 1

    After item 2, k=1 and total=2.

  3. Maintain 2

    After item 4, k=2 and total=6.

  4. Terminate

    After item 6, k=3 and total=12.

TRY BEFORE CHECKING

Exercises with feedback

Enable JavaScript for feedback, or use the printed exercises.

MAKE SOMETHING YOU CAN EXPLAIN

Your practical challenge

Explain initialisation, maintenance and termination for the example. Add assumptions about numeric inputs.

Review your evidence

These ticks are your self-review. They do not automatically assess project quality. Ask an adult or partner to review what you can show.

Use the skill in a new situation

Adapt the reasoning to counting matching items.

Choose a different space for another learner on this browser.

Notes and checks use this browser, separate from school sign-in.

Each space keeps each grade separate. These spaces are not private accounts; use separate browser profiles for privacy on a shared device. About your practice data

Next: Evaluate whether AI is appropriate →All six experiences