# What is an algorithm? [Programming guides](README.md) An **algorithm** is a clear method for solving a problem. It describes steps and rules that you can follow. You can invent an algorithm on paper before writing any code. A program expresses those ideas in a language the computer can execute. The same idea can be written in Pliro, another programming language, or ordinary sentences. ## Plan a treasure hunt Suppose a treasure hunter needs to count all the coins in three boxes. One method is: start at zero, open each box in turn, add its coins to the total, and report the total after the last box. This plan tells us where to start, what to repeat, and when to stop. “Find the answer somehow” would not tell our treasure hunter enough. ## Turn the plan into code You will use a variable, a list, and a `for` loop. A variable gives a stored value a name. A list keeps several values in order. ```pliro # language: en let boxes = [3, 5, 2] let total = 0 for coins in boxes: set total = total + coins say total ``` `total` starts at zero. On each visit, `coins` is the number in the next box. `set` stores the updated total. The last `say` is outside the loop, so it runs after all boxes have been counted. ## Predict, then run Write the total after each box on paper. What final number should appear? ```text 10 ``` Your intermediate totals should be 3, 8, and 10. Those intermediate results help you check the method, not just the final answer. ## Your challenge Add a fourth box containing 4 coins. Can the same algorithm handle it without changing the loop? Then try an empty list: what total would make sense when there are no boxes? ## A common mistake Starting with `total = 1` counts an extra coin that was never in a box. Check the starting value as carefully as the repeated steps. For counting or adding, zero is often the right starting point. ## Where next? [Breaking problems into steps](decomposition.md) · [Lists](../syntax/list.md) · [Testing](testing.md)