C. Algebra · Patterns, Equality and CodingCoding: Step-by-Step Instructions
C3.1About 35 minutes
Learning goals- I know that code is a list of instructions, followed in order.
- I can write code to move a robot on a grid.
- I can write code to solve a math problem.
- I can run (follow) my code to see what happens.
Words to know
code
Instructions written so a computer or robot can follow them.
instruction
One step that tells what to do.
sequence
Steps that happen one after another, in order.
run (execute)
To follow the code, step by step, to see what happens.
grid
Rows and columns of squares, like a game board.
Meet Beep the robot!
Beep is a little robot. Beep is very good at following instructions. But Beep cannot think on its own. Beep does exactly what you say, in order, one step at a time.
A list of instructions for a robot or a computer is called code. Writing code is called coding.
Steps in order: a sequence
Coding is all about doing steps in the right order. Steps that happen one after another are called a sequence.
You follow sequences every day! Here is the code for getting dressed for snow:
1. Put on snow pants
2. Put on boots
3. Put on coat
4. Put on hat
5. Put on mittens
Code for getting ready to play in the snow. Mittens go on last so your hands can do up your coat!
Order matters
What would happen if you put on your boots before your snow pants? The snow pants would not fit over the boots! In code, changing the order can change what happens.
Coding Beep on a grid
Beep lives on a grid. Beep can follow these instructions:
➡ Move right (a number tells how many squares)⬅ Move left⬆ Move up⬇ Move down
Beep wants to get to the star ⭐.
Beep starts in the bottom-left square. The star is 3 squares to the right and 2 squares up. The dashed line shows Beep's path.Worked exampleWrite code to reach the star
Write code to move Beep from the bottom-left square to the star.
- Put your finger on Beep.
- Count the squares to the right until you are under the star: 1, 2, 3. That is Move right 3.
- Count the squares up to the star: 1, 2. That is Move up 2.
- Write the steps in order.
- Run the code: move your finger right 3, then up 2. You land on the star!
The code is:
➡ Move right 3
⬆ Move up 2
START
➡ Move right 3
⬆ Move up 2
STOP ⭐
Beep's code to reach the star.
More than one way
Another code also works: ⬆ Move up 2 then ➡ Move right 3. There is often more than one correct code. Can you find a third way? (Try: Move right 1, Move up 2, Move right 2.)
Forward and turn
Some robots use Move forward and Turn instead of arrows. Forward means the way the robot's face is pointing. Pretend Beep is facing the right:
START (facing right ➡)
➡ Move forward 3
↰ Turn left (now facing up ⬆)
⬆ Move forward 2
STOP ⭐
The same path as before, written with forward and turn. A left turn makes Beep face up.
Code can do math, too!
Computers do math by following code. Here is code that counts by 5s, like counting nickels in a jar.
START with 0
Add 5
Add 5
Add 5
Add 5
SAY the number
Run it: 0 → 5 → 10 → 15 → 20. Beep says 20.
Worked exampleRun the math code
What number does this code say?
START with 10 → Add 10 → Add 10 → Take away 5 → SAY the number
- Start with 10.
- Add 10: 10 + 10 = 20.
- Add 10: 20 + 10 = 30.
- Take away 5: 30 − 5 = 25.
- Say the number: 25.
Worked exampleWrite code for a story problem
There are 4 children on the toboggan hill. Then 3 more come. Then 2 more come. Write code that finds how many children there are.
- Start with the children who were there first:
START with 4. - 3 more come:
Add 3. - 2 more come:
Add 2. - Tell the answer:
SAY the number. - Run it: 4 → 7 → 9.
START with 4 → Add 3 → Add 2 → SAY the number. The code says 9 children.
Practice grid: Beep starts in the top row, 2nd square. The star is 3 squares to the right and 2 squares down.Your turn
1Look at the practice grid. Write code to get Beep to the star.
➡ Move right 3, ⬇ Move down 2. (Or ⬇ Move down 2, ➡ Move right 3.)
2Run this code. Start with 0, Add 2, Add 2, Add 2. What number do you get?
3Run this code. Start with 20, Take away 10, Add 5. What number do you get?
4Write code that starts with 0 and counts by 10s to 30.
START with 0, Add 10, Add 10, Add 10, SAY the number (it says 30).
5Write the code for brushing your teeth in 4 steps.
For example: 1. Put toothpaste on the brush. 2. Brush your teeth. 3. Spit. 4. Rinse the brush.
6Beep is facing right. The code says Move forward 2. Which way does Beep move?
To the right, 2 squares. Forward is the way Beep is facing.
Just for funWhat if Beep followed the snow code in a mixed-up order and put on mittens first? Beep would try to zip up its coat with big puffy mitten hands. Good luck, Beep!
Hands-on activityBe the robot
You need: painter's tape or chalk (or floor tiles), a toy to be the "star", and paper.
- Make a grid on the floor, 4 squares by 4 squares. Tiles work great!
- A grown-up places the toy on a square.
- Write the code on paper with arrows, like
➡ Move right 2, ⬆ Move up 1. - The grown-up is the robot. They must follow the code exactly, step by step, even if it is wrong!
- Did the robot reach the toy? If yes, hooray! If not, fix the code and try again.
- Switch: now you are the robot.
Keep trying
Coders almost never get it right the first time. That is normal! Try, check, and try again. That is how real coders work.
More practice: warm-up
1The star is 4 squares to the right of Beep, in the same row. Write the code.
2Run this code. START with 0 → Add 1 → Add 1 → Add 1 → SAY the number. What does it say?
3Put these steps for planting a seed in order: Water the seed. Dig a hole. Cover it with soil. Put the seed in the hole.
- Dig a hole. 2. Put the seed in the hole. 3. Cover it with soil. 4. Water the seed.
4Beep runs ⬆ Move up 3. Which way does Beep move, and how far?
5True or false? A robot can skip a step in the code if it wants to.
False. A robot does exactly what the code says, every step, in order.
More practice: on your own
1The star is 2 squares to the left and 4 squares up from Beep. Write code to get Beep to the star.
⬅ Move left 2, ⬆ Move up 4. (Or ⬆ Move up 4, ⬅ Move left 2.) Count the squares across first, then the squares up.
2Run this code. START with 10 → Add 5 → Add 5 → Take away 10 → SAY the number. What does it say?
10. 10 → 15 → 20 → 10. Adding 5 two times and then taking away 10 brings you back to where you started.
3There are 5 birds at the bird feeder. 4 more come. Then 2 fly away. Write code that finds how many birds are left.
START with 5 → Add 4 → Take away 2 → SAY the number. Run it: 5 → 9 → 7. The code says 7 birds.
4Beep is facing up ⬆. The code says Move forward 3. Which way does Beep move?
Up, 3 squares. Forward is the way Beep is facing, and Beep is facing up.
5Write code that starts with 0 and counts by 5s to 25.
START with 0, Add 5, Add 5, Add 5, Add 5, Add 5, SAY the number. Run it: 0 → 5 → 10 → 15 → 20 → 25. It takes 5 Add 5 steps.
Challenge
1Code A: ➡ Move right 1, ⬆ Move up 3, ➡ Move right 2. Code B: ⬆ Move up 3, ➡ Move right 3. Beep starts in the same square both times. Do the two codes end in the same square? How do you know?
Yes. Code A moves right 1 + 2 = 3 squares and up 3 squares. Code B also moves right 3 and up 3. The paths are different, but Beep ends in the same square.
2Beep starts facing right ➡. The code is Move forward 2, Turn left, Move forward 1. Where does Beep end, and which way is Beep facing?
Beep ends 2 squares right and 1 square up from the start, facing up ⬆. Forward 2 goes right. A left turn makes Beep face up. Forward 1 then goes up.
3Write code to go from 0 to 30 using only Add 10 and Add 5. Use as few steps as you can. How do you know it is the fewest?
START with 0, Add 10, Add 10, Add 10, SAY the number. That is 3 add steps: 0 → 10 → 20 → 30. Adding 10 is the biggest jump, so it gets there fastest. Using only Add 5 would take 6 steps.
Check your understandingQuiz
2. Beep starts at a square. The code is ➡ Move right 2, ⬆ Move up 1. Where does Beep end?
3. What number does this code say? START with 5 → Add 5 → Add 5 → SAY the number
4. Why does the order of steps matter in code?
5. What number does this code say? START with 2 → Add 2 → Add 2 → Add 2 → SAY the number
6. The star is 1 square right and 3 squares up from Beep. Which code works?
For parents and teachersCoding in Grade 1 is about sequences: precise steps, in order. No computer is needed. The same thinking supports reading directions, math procedures and problem solving.
Common mistakes
- Counting the starting square as a move. Show that Move right 1 means one hop to the next square. Have your child hop their finger, saying "one" as they land.
- Mixing up left and right. A sticker or bracelet on one hand can help.
- With forward/turn code, forgetting that turning does not move the robot, it only changes the direction it faces.
How to help
- Play "Be the robot" often. Follow your child's code exactly, even when it leads you into a wall (they love this!).
- Write "code" for routines: making a sandwich, getting ready for bed.
- Free, screen-optional options: ScratchJr (app) or simple unplugged board games with arrow cards.