MyLeoNes™

Counters that change — Computing, 4–6 years

A computer can keep a number and change it when something happens. Scores, turns and collected objects all need this small but powerful idea.

A number that remembers

A counter is a number that the computer keeps while something is happening. It can start at 0, go up when you collect a star, or go down when you use one. The number gives the program a simple memory of what has happened.

Why count inside a program

A game needs to know more than what is visible right now. It must remember how many stars were collected, how many lives remain or whose turn it is. Changing a stored number is more reliable than asking a person to remember every event.

Collecting three stars

Set the counter to 0 before the game starts. The player collects one star, so the program changes 0 to 1. A second star changes 1 to 2, and a third changes 2 to 3. When the counter reaches 3, the program can show “You win”.

The forgotten change

A common mistake is showing a new star but forgetting to change the counter. That makes sense because the picture is easy to notice, while the hidden number is not. The program must connect the event to the change: one star collected means add 1, exactly once.

Scores and stock

Counters appear in games, where they show points or lives, and in a music player, where they show the track number. A shop system can count how many items remain. In each case, the number changes because a real event has happened.

Keep exploring

Other languages

Loading MyLeoNes™…