Computing · Stage 5

Subroutines: Reuse Your Code

Programs & Judgement · subroutines · name a block of code and reuse it

✦ Computing📘 Stage 5 · S5⏱ ~12 min🧒 Ages 9–10★ Free to start
I can name a block of code and reuse it.
Kavi the owl for Computing
📖

Kavi Teaches the Robot One Trick

Kavi's robot had to wave hello to ten friends. "I am NOT writing raise, shake, lower ten times!" hooted Kavi. So Kavi taught the robot one trick and gave it a name: define wave(): raise · shake · lower. Now Kavi just writes wave() and all three steps run. "A named block of code I can run again and again is a subroutine," said Kavi. "I define it once, then call it as many times as I like — and if I want to change the wave, I fix it in one place, not ten."

🎓

What your child will learn

1Name it once, call it again and againA subroutine is a named block of steps. You define the block once, then call its name to run the whole block — as many times as you like. Tap each part to hear its job.
2One block, used twiceThis program defines wave() once, then calls it twice. Press ▶ Run and watch each call run the SAME three steps again.
3Copy the code, or define it onceTo wave 3 times you could copy the steps three times — or define a subroutine once and call it. Tap each card to see the difference.
4How many beeps?Read the program, then say how many beeps run in all. Reveal to check.
🔍

A peek inside

Kavi writes define greet(): say hello, wave near the top, and later writes greet() on its own line. What does that second line do?
the block is defined once; writing its name on its own runs the block

Try this at home: A named block of code that you can run again and again is called a ____.

Ready to play and learn?

Start the free interactive lesson, or print the handout for screen-free play.

Part of Computing · Stage 5 · S5 on KAVI Academy — a secular, whole-child learning platform for ages 5–12.