Trek
LOOP / ITERATION — *keeps going around until the work is done.*
Listen along — Trek
Loading audio…
Press play to listen along. The line being read lights up as you go.
Show full transcript
Loading transcript…
Chapter 3 — Trek and the Circular Track
Trek was not a furry creature. He wasn’t a squishy blob either. Trek was a small, round track. It was painted bright yellow. Little arrows pointed all around the track. They showed the way to go. On Trek’s chest was a tiny screen. It showed numbers.
Trek’s job was to loop. He did things again and again. Until they were done. He was the master of repetition. The king of doing it over. Trek showed how to run the same block of code repeatedly. This is called looping or iteration.
One sunny morning, Pip zoomed into the CodeRealm plaza. Pip was a zippy little Variable. Always changing, always moving. Pip held a big, empty bucket. “Trek!” Pip squeaked. “We need water balloons!”
Trek blinked his single, round eye. He looked at the bucket. Then at Pip.
Pip bounced on their toes. “Lots of them! For the big CodeRealm water fight!”
Trek rolled over to the Water Spout. It gurgled happily. He picked up a small, blue balloon. He held it under the spout. Water rushed in. The balloon grew. POP! It was full. Trek tied it off. He put it in the bucket. His chest counter flashed: ‘1’.
Pip clapped. “Great! Now do it again!”
Trek picked up another balloon. Filled it. Tied it. Placed it. His counter clicked: ‘2’. He kept going. ‘3’. ‘4’. ‘5’.
Pip suddenly looked worried. “Wait! How many do we need?”
Trek paused. The arrows on his track glowed faintly.
Pip scratched their head. “Oh! I forgot to say! We need exactly ten balloons!”
Trek’s eye brightened. He understood. A stopping condition!
He went back to work. ‘6’. ‘7’. ‘8’. ‘9’. ‘10’. When the counter hit ‘10’, Trek stopped. He sat still. The arrows faded. The bucket was full. Pip cheered. “Perfect, Trek!”
What if Pip hadn’t said ‘ten’? Trek would have kept going. And going. And going. The CodeRealm would be buried in balloons. Forever. That’s why a stopping condition is super important. You always need one. Otherwise, you get an infinite loop. That’s not good.
Trek’s little chest screen was his counter variable. It kept track. It knew how many times he had looped. It was like a scoreboard for his work. Very useful.
Pip looked at the full bucket. “Wow! That was fast!”
Pip thought for a moment. “I could have filled them one by one.”
Trek just blinked. Filling ten balloons, one by one, would take a long time. And what if they needed a hundred? Or a thousand? Trek’s way was better. He just repeated the same steps. Over and over. No need to write down ‘fill balloon, tie balloon, put in bucket’ ten times. Just say ‘do it ten times’. That’s the power of a loop. It helps you avoid copy-paste.
Suddenly, a small, green balloon rolled by.
Pip gasped. “Oh no! That one has a tiny hole!”
Trek was about to pick it up. He saw the hole. He nudged it away with a wheel. He continued to the next good balloon. He skipped the bad one. No need to fill a leaky balloon.
Later, Pip pointed. “We need a red balloon! Just one!”
Trek started filling. Blue. Yellow. Green. No red. Then he found a bright red one. He filled it quickly. He tied it. He put it in a special spot. Then he stopped. He broke out of his loop. He didn’t need any more. Just that one red one. Sometimes you need to stop early. Or skip a step. That’s what break and continue are for. They control the flow of the loop.
Pip ran back. “New plan, Trek!”
Trek looked up. Pip had a new list. “We need five buckets of ten balloons each!”
Trek’s eye widened a little. That was a lot of balloons. He thought about it. He had just filled one bucket of ten balloons. Now he needed to do that whole process five times. It was a loop inside a loop! A nested loop!
First, he would loop ten times to fill one bucket. Then, he would loop five times to fill five buckets. His little counter screen showed ‘Bucket 1 of 5’ and ‘Balloon 1 of 10’. It was tricky. But Trek was good at repeating. He started his work. Fill, tie, place. Ten times. Bucket one was done. He moved it aside. Then he started on bucket two. Fill, tie, place. Ten times again. It took a while. But soon, five full buckets sat ready.
Pip stared. “Amazing, Trek! You made fifty balloons!”
Trek just blinked. It was all just repeating. But with more layers.
Just then, a long, slinky figure slithered by. It was Coil. Coil was a master of recursion. Coil could do things by calling himself. Over and over. Like a loop, but a little different. A twisty, turny way.
Coil waved a long arm. “Good work, Trek! Keep on looping!”
Trek nodded. Loops and recursion. They were like cousins. Both were about doing things again. Until the job was done.
Trek was the loop. He repeated the work. Until it was done. A stopping condition was always needed. No endless loops! He wasn’t a runner. He was a repeater. The best in CodeRealm.
The CodeRealm ensemble
Trek is part of CodeRealm's distributed-narrative cast. Each character embodies a different curricular primitive; together they teach the full subject.
-
Stash
Variable / storage — the labeled box that holds a value until you call for it
-
Fork
Conditional / branching — chooses a path based on what's true right now
-
Module
Function / encapsulation — does one job well and can be called anywhere
-
Glitch
Debugging / inspection — finds bugs gently, never shaming; 'there's always a reason'
-
Order
Sequence / syntax — reminds you that order matters in code
-
Row
A list: many values lined up in a numbered row, so you can grab item number three instantly or walk through them one by one.
-
Port
Input and output: the doorway that brings information in from the world (a key press, a sensor) and sends results back out.
-
Ping
An event: a waiting bell that does nothing until its trigger happens, then runs its code the instant it is struck.
-
Shuffle
Randomness: a fresh unpredictable value each time — a dice roll, a shuffled deck — so a program can surprise, vary, and stay fair.