Every program ever written is built from three shapes and nothing else. Learn them as pictures now and the C++ keywords later will be spelling, not new ideas.
Every program ever written — your homework, your phone, the flight system on a plane — is built from only three shapes: do this then that, choose between paths, and do it again.
That is not a simplification for beginners. It is a proven fact about computing, and it is genuinely all there is. Everything that looks more complicated than this is these three shapes nested inside each other, sometimes thousands deep.
Their proper names are sequence, selection and repetition. Your lecturer will use those words. They mean then, if, and again.
When you eventually meet C++ you will see if, else, while and for and they will look like new things to memorise. They are not new. They are these three shapes with punctuation. If you know the shapes now, the syntax later is spelling, not thinking.
Each of the three below is a real program written as a picture. Run them. On the second one, change the weather first and watch the path go somewhere else.
Pick a shape, then press play. Watch which box lights up next.
Sequence is easy. Choice is easy. Repetition is where almost every beginner loses an afternoon, and it is always one of two things.
Either the thing that is supposed to change never changes — you forgot to add 1 to count, so it stays at 1 forever, the answer to “is count 3 or less?” is always yes, and the program runs until you kill it. That is an infinite loop, and you will write one this semester. Everyone does.
Or it runs one time too many or one time too few. Look at the loop above: it does three push-ups, not four, and getting that exactly right is called an off-by-one error. It has a name because it is that common.
Go back and imagine the “Add 1 to count” box is missing. Walk it yourself: count is 1, is 1 three or less? Yes. Push-up. Back to the question. Count is still 1… Feeling why it never stops is worth more than being told it does not.
Name an everyday routine out loud — making coffee, doing laundry, getting to campus, checking your phone in the morning.
Call out each shape as it appears. “That is a then.” “That is an if.” “That is an again — and what makes it stop?”
The killer question is the last one: what makes it stop? Laundry repeats until the basket is empty. Scrolling repeats until… and that is a real conversation about infinite loops. Swap roles after two routines.
Sequence, selection, repetition. Every program you will ever read is these three, nested.
Something inside must change, or the answer to the question never changes and it runs forever.
if, else, while, for are not new ideas. They are these shapes with brackets.
Not recall — these are the shapes an exam actually uses. Every answer below was produced by compiling and running the code, so if you disagree with one, the compiler is the one to believe.
Have a real go before revealing. Being wrong here is worth more than being right in three weeks.
How many shapes is every program built from?
A loop checks “is count 3 or less?” but nothing inside ever changes count. What happens?
In an if / else, how many of the two branches run?
← back to all 12 levels · stuck on anything? ask peter.