Building Blocks of CodeSeven days of stories, drawing, and play
Sequences, conditionals, loops, variables, functions, parameters, and AND/OR — taught through a horse called Sparkle and a lot of rainbows. No computer required.
Table of contents
Each day introduces one idea, shows it twice (once with Sparkle the horse, once with something else), and finishes with something to draw. Work through one a day or run them together; they build on each other in order.
Download this lesson as Markdown
Day 1: Sequences (steps in order)
A sequence is a set of instructions followed in order, one after another. Computers do exactly what you tell them, in exactly the order you say it. If you skip a step or mix up the order, things go wrong!
"When we tell a computer what to do, we have to give it steps in order, just like a recipe! If we mix up the steps, things get silly."
Let's say we want to get Sparkle the horse ready for a ride. What do we do first?
Step 1: Find Sparkle in the field
Step 2: Put on the saddle
Step 3: Put on the bridle
Step 4: Climb on
Step 5: Say "Let's go!"
What if we tried to climb on Sparkle BEFORE we put the saddle on? That would be uncomfortable! Computers are the same way. They need the steps in the right order.
Drawing idea
Draw 4–5 boxes in a row, like a comic strip. Draw or describe what happens in each box to "get the horse ready." Number the boxes together.
Day 2: Conditionals (if / then)
A conditional is how computers make decisions. It's an "if this, then that" rule. The computer checks if something is true, and if it is, it does something.
"Computers can make choices! They use a special rule called 'if-then.' Let's try it with rainbows!"
When do we see a rainbow?
IF it rained AND the sun comes out
THEN a rainbow appears!
Try another one with horses:
IF Sparkle is hungry
THEN give Sparkle an apple
And one with math:
IF 2 + 2 equals 4
THEN you got it right!
Make it silly
Make up your own if-then rules and act them out!
- IF I clap my hands, THEN you neigh like a horse!
- IF I say "rainbow," THEN you jump!
Drawing idea
Draw a simple flowchart: a cloud with rain on one side, an arrow pointing to a rainbow. Label it "IF rain + sun → THEN rainbow!"
Day 3: Loops (doing something over and over)
A loop tells the computer to repeat something. Instead of writing the same instruction 100 times, we just say "do this 100 times" or "keep doing this until something happens."
- "Do this X times" (FOR loop) — repeat a set number of times
- "Keep doing this while…" (WHILE loop) — repeat until something changes
"Sometimes we want to do something over and over. Instead of saying it a million times, we can use a LOOP!"
FOR loop. Let's say Sparkle is trotting around a track. We want her to go around 3 times.
DO THIS 3 TIMES:
Sparkle trots around the track
We don't say "trot, trot, trot." We just say "do it 3 times!"
Math loop. Let's count by ones!
Start at 1
DO THIS 5 TIMES:
Say the number
Add 1
(1... 2... 3... 4... 5!)
WHILE loop. What if we don't know exactly how many times? We keep going UNTIL something happens.
WHILE it is still raining:
Wait and watch the sky
(When the rain stops and sun appears...)
Rainbow time!
The loop keeps going WHILE it's raining. When the rain stops, we "break out" of the loop and get our rainbow!
Drawing idea
Draw a circular arrow, like a recycling symbol, with a horse inside it. Write "go around 3 times" next to it.
Day 4: Variables (boxes that hold things)
A variable is like a labelled box that holds information. You give it a name, and you can put something inside — a number, a word, anything. Later you can look inside, change what's in it, or use it somewhere else.
"In coding, we have special boxes called variables. We give each box a name, and we can put something inside!"
Let's make a box called "apples." This box holds how many apples Sparkle has eaten today.
apples = 0 (The box starts empty, zero apples!)
Sparkle eats an apple...
apples = 1 (Now there's 1 in the box!)
Sparkle eats another apple...
apples = 2 (Now there's 2!)
The box is called "apples," and the number inside changes!
Rainbow example:
rainbow_colors = 7
"How many colors in a rainbow?"
Look in the rainbow_colors box... it says 7!
Math example:
my_number = 5
my_number + 3 = ?
(Look in the box... 5! So 5 + 3 = 8!)
Drawing idea
Draw a box, like a shoebox, and write "apples" on the outside. Inside, write a number. Practise "changing" the number by erasing and writing a new one — that's the variable updating.
Day 5: Functions (giving instructions a name)
A function is a set of instructions bundled together with a name. Instead of repeating all the steps every time, you "call" the function by name and it does all the steps for you.
Think of it like teaching someone a dance move and naming it. Once they know "The Rainbow Spin," you just say the name and they do all the steps.
"Sometimes we do the same steps over and over. Instead of saying all the steps every time, we can give them a name! That's called a function."
Let's teach Sparkle a trick called "take_a_bow"!
FUNCTION take_a_bow:
Bend front legs
Lower head
Stand back up
Now whenever we say "take_a_bow," Sparkle knows to do ALL those steps!
Sparkle, take_a_bow!
(Sparkle bends legs, lowers head, stands up)
Rainbow example:
FUNCTION draw_rainbow:
Draw a red arch
Draw an orange arch
Draw a yellow arch
Draw a green arch
Draw a blue arch
Draw a purple arch
Now we can just say "draw_rainbow" instead of listing every colour!
Drawing idea
Draw Sparkle the horse with a speech bubble that says "take_a_bow!" Then draw arrows showing each step Sparkle does.
Day 6: Parameters (giving functions extra info)
Sometimes a function needs extra information to do its job. That extra info is called a parameter. It's like telling someone "make me a sandwich," but they need to know WHAT KIND of sandwich.
"Remember functions? Sometimes they need extra information. Like if I say 'feed Sparkle,' you might ask… feed her WHAT? That extra info is called a parameter!"
FUNCTION feed_sparkle(food):
Pick up the food
Give it to Sparkle
Sparkle eats it!
feed_sparkle(apple) --> Sparkle eats an apple!
feed_sparkle(carrot) --> Sparkle eats a carrot!
feed_sparkle(hay) --> Sparkle eats hay!
Same function, but we change what's in the parentheses — the parameter — to feed her different things!
Rainbow example:
FUNCTION paint_color(color):
Dip brush in color
Paint an arch
paint_color(red) --> Red arch!
paint_color(orange) --> Orange arch!
paint_color(yellow) --> Yellow arch!
Math example:
FUNCTION add_five(number):
Take the number
Add 5
Say the answer!
add_five(2) --> 7!
add_five(10) --> 15!
add_five(0) --> 5!
We made a function that adds 5 to ANY number we give it!
Drawing idea
Draw the feed_sparkle function like a machine: a box with a slot at the top where you drop in the food, and Sparkle at the bottom eating. Label the slot "food goes here!"
Day 7: AND & OR (combining conditions)
AND and OR let us combine conditions. These help computers make smarter decisions.
- AND — both sides must be true for the whole thing to be true
- OR — only one side needs to be true for the whole thing to be true
"Remember if-then? Sometimes we need to check MORE than one thing before we decide. We can use AND and OR to combine our checks!"
Can Sparkle go on a trail ride? Let's check two things:
IF Sparkle is healthy AND the weather is nice
THEN we can go on a trail ride!
Both must be true!
Sparkle healthy? YES
Weather nice? YES
Result: YES, let's ride!
What if one is wrong?
Sparkle healthy? YES
Weather nice? NO (it's storming!)
Result: NO ride today.
With AND, if even ONE thing is false, the whole thing is false. Both must be true!
Now let's try OR. What snack should Sparkle get?
IF Sparkle did a trick OR Sparkle was extra good
THEN give Sparkle a treat!
Only ONE needs to be true!
Did a trick? YES
Was extra good? NO
Result: Treat time! (doing a trick was enough!)
With OR, only ONE thing needs to be true. If either one is true, the whole thing is true!
Rainbow example with AND:
IF it rained AND the sun is out
THEN we see a rainbow!
Rain? YES
Sun? YES
Result: RAINBOW!
Rain? YES
Sun? NO
Result: No rainbow yet... keep waiting!
Math example with OR:
IF the number is less than 5 OR the number is greater than 10
THEN say "outside the middle!"
Number = 3 --> 3 < 5 is YES --> "outside the middle!"
Number = 7 --> both NO --> (nothing happens, 7 is in the middle)
Number = 12 --> 12 > 10 is YES --> "outside the middle!"
Act it out
Try these AND/OR rules with a friend:
- IF you are standing AND you are smiling, THEN spin around!
- IF you are wearing red OR you are wearing blue, THEN clap your hands!
- IF it is daytime AND you are outside OR you have a flashlight, THEN you can see!
Drawing idea
Draw two gates: an AND gate, where both arrows must go in for one to come out, and an OR gate, where either arrow going in makes one come out. Label them.
Putting it all together
Let's get Sparkle ready for a ride and find a rainbow!
FUNCTION get_ready(animal):
Put on saddle
Put on bridle
Climb on animal
horse_name = "Sparkle"
get_ready(Sparkle)
DO THIS 3 TIMES:
Trot around the field
WHILE it is raining:
Keep trotting under a tree
IF rain stops AND sun comes out:
rainbow_colors = 7
"Look! A rainbow with 7 colors!"
Sparkle, take_a_bow!
Can you find each concept?
- Sequence — the order of the steps
- Loop — trotting 3 times, waiting while it rains
- Conditional — rain stops → rainbow!
- Variable —
horse_name,rainbow_colors - Function —
get_ready,take_a_bow - Parameter — Sparkle, the animal passed to
get_ready - AND — rain stops AND sun comes out, both have to happen
Quick reference
| Concept | What it means | Example |
|---|---|---|
| Sequence | Steps in order | 1. Saddle → 2. Bridle → 3. Ride! |
| Conditional | If this, then that | IF hungry → THEN eat |
| Loop | Repeat! | Trot 3 times |
| Variable | A box with a name | apples = 5 |
| Function | Named instructions | take_a_bow! |
| Parameter | Extra info for a function | feed(carrot) |
| AND / OR | Combine conditions | IF rain AND sun → rainbow |