Play CodeRealm

Fork

CONDITIONAL / BRANCHING

Loading audio…

Press play to listen along. The line being read lights up as you go.

Show full transcript

Loading transcript…

01 Opening
Fork beat 1 of 5

Fork wasn't a fluffy squirrel or a talking badger. Fork was, well, a fork — not the dinner kind, but a small painted wooden sign, the sort you'd see on a tiny path. Above it floated a little diamond shape with the word IF inside, and two arrows pointed away from the diamond: one left, one right.

"Alright, team! Meet Fork!" Loop clapped her hands — Loop always sounded excited. "Fork helps us make choices. Not Fork's choices, mind you. Our choices. Or really, the program's choices." I looked at Fork. It just sat there, not deciding anything. "See the diamond?" Loop asked. "It holds a question — a condition. If the answer is YES, we go one way. If it's NO, we go the other."

02 Fork
Fork beat 2 of 5

"Let's say we want a super-sparkle from the Sparkle Collector," Loop said, patting the big clunky contraption that usually just coughed out regular sparkles. "The machine's picky. It only gives a super-sparkle if you already have exactly five regular sparkles." She pointed at Fork's diamond. "So the question in here is: Do we have five sparkles?"

She traced the left arrow. "If the answer is YES — this way. The program tells the machine: super-sparkle, please. Hooray!" Then the right arrow. "If NO — that way. Go find more sparkles. Boo."

"So Fork doesn't decide?" I asked. "It just shows the paths?"

"Exactly! Fork is a branch-point, not a decision-maker. The condition makes the decision. Condition true, branch one way. Condition false, branch the other."

03 Fork
Fork beat 3 of 5

"Conditions are like yes-or-no questions," Loop went on. "They're either TRUE or FALSE. No 'maybe' allowed in code — it's super strict. 'Is the sky blue?' TRUE. 'Are pigs flying right now?' FALSE — unless you know something I don't." I giggled. "So a condition is just a fact we check. We can ask if two things are the same with two equals signs: ==. Is sparkles == 5? We ask if they're not the same with !=. Is machine != broken?" She was on a roll. "We can ask if one thing's bigger or smaller — > and <. Is your_age > 9? Is shoe_size < 12? Every one of these gives back a TRUE or a FALSE. That's all a condition ever does."

04 Fork
Fork beat 4 of 5

"What if we need to ask two questions at once?" I wondered.

"Great thinking! We combine conditions with AND and OR." Loop nodded at the machine. "Maybe it only works if you have five sparkles AND the machine is switched on. For an AND, both must be true — one false, and you branch the other way. For an OR, only one needs to be true: 'five sparkles OR it's your birthday' gets you the super-sparkle either way." She grinned. "Verity, over in DiscreteQuest, taught us all about AND and OR — she says they're the building blocks of good thinking. And here's the wild part: the true path can hold another Fork inside it. That's called nesting — a choice that leads to another choice, like a tree of paths. If seven days each need a different path, we could stack 'if... else if... else if...' — but there's a tidier way called a match or switch statement, a neat little menu you pick from. Loop loves tidy code."

05 Closing
Fork beat 5 of 5

"Does Fork know the answer ahead of time?" I asked. "Like, whether I have five sparkles before I even get there?"

"Nope — and that's the clever part," Loop said, tapping the diamond. "The condition is checked right when you need it. Not decided in advance. It depends on what's true right now. Different inputs, different paths — that's the whole magic of branching. So remember: Fork is the conditional. If a thing is true, go this way; if not, go that way. Fork's a branch-point, not a decision-maker. It's not hard — true, this way; false, that way."

I looked at Fork's two arrows one more time, and something in my chest went quiet and easy. All those choices that used to make me feel wobbly and stuck — they were just a question with a yes and a no. I felt lighter, like I could stand at a fork in the path now and not be scared of it. Just check the condition. Then go.

Hear it as an audio drama

A short play starring Fork, from CodeRealm. Different voices, same idea. Listen any time after you read.

Loading audio…

Read the drama script
  1. Narrator: From Spark and Anvil and CodeRealm — this is Fork, in chapter 1 of the CodeRealm cast.
  2. Narrator: This drama uses an AI-generated voice. Voiced via Gemini 2.5.
  3. Narrator: Fork is not an animal-tween. Fork is a deliberately abstract concrete-object-figure. A small painted fork-in-the-path figure with a small "if" diamond above it. Two arrows lead from the diamond to two distinct paths.
  4. Narrator: The diamond holds a condition. The arrows lead to what happens if the condition is true — one path — or what happens if it's false — the other path.
  5. Narrator: Because Fork is not a personified character, the cast's mentor Loop speaks on Fork's behalf. Loop describes the idea.
  6. Loop: Fork is the conditional. If a thing is true, go this way. If not, go that way. Programs branch based on conditions. Fork is not a decision-maker. Fork is a branch-point.
  7. Narrator: Fork is all about conditional and branching. If a condition is true, the program goes one way. If false, it goes the other way. That's if-else — the foundation of program control flow.
  8. Loop: The syntax in most languages — if (condition), do this. Else, do that. The condition is a question the program asks. The answer is true or false. The path depends on the answer.
  9. Loop: Conditions evaluate to true or false. Boolean output. The condition itself is an expression — a comparison, a check, a function call. But its result is always one of two things. True. Or false.
  10. Narrator: Loop walks through the most common conditions a young programmer learns.
  11. Loop: Equality. Is X equal to Y? Two equals signs in most languages — that's the comparison. Different from one equals sign, which is assignment.
  12. Loop: Inequality. Is X not equal to Y? Exclamation point and equals sign. The negation of equality.
  13. Loop: Greater-than and less-than. Is X greater than Y? Is X less than Y? Or greater-than-or-equal-to, less-than-or-equal-to. The numeric comparisons.
  14. Loop: Multiple conditions can combine. AND. OR. NOT. Two conditions joined with AND — both must be true. Two conditions joined with OR — at least one must be true. NOT flips a true to a false and a false to a true.
  15. Loop: That's Boolean logic. The DiscreteQuest cast member Verity teaches the same thing from the math side. AND, OR, NOT — same operators, same rules, just visited from a different angle.
  16. Narrator: Loop shows a more complex branching pattern.
  17. Loop: Nested conditionals. An if-statement inside an if-statement. Build up complex branching one layer at a time. If the outer condition is true, then check the inner condition. The two layers together give you four possible branches.
  18. Loop: Match statements or switch statements. Multi-way branches. Cleaner code than long chains of if-elif-elif-else. The program checks a value against several possible patterns. Each pattern has its own branch.
  19. Narrator: Loop pauses on a crucial detail.
  20. Loop: The condition must be checked at runtime. The program does not know which branch will be taken until the moment it runs. Different inputs lead to different paths. The same program, with different data, traces different routes through the code.
  21. Loop: That's what makes programs adaptive. They respond to what's true at the moment of execution. A weather-app shows you rain or sun based on the actual forecast. A game shows you "you won" or "try again" based on the actual score. The branching is what lets the program meet the world.
  22. Narrator: Fork itself is the painted figure on the desk. The little diamond. The two arrows. Static. Concrete. Anti-personification.
  23. Loop: Fork stays silent. The painted figure does the teaching. If true, this way. If false, that way. Conditions evaluate to true or false. Programs branch on conditions. The branch-point is the idea.
  24. Loop: Not hard. Branch based on condition. If true, this way. If false, that way.
  25. Narrator: Loop steps back. The Fork figure sits in its frame on the workbench. The diamond holds the next condition. The two arrows wait for the next runtime check.
  26. Narrator: If true, this way. If false, that way. The two-path decision.
  27. Narrator: You've been listening to a Spark and Anvil chapter, written by the Spark and Anvil writing team for ages 9 to 14.
  28. Narrator: Apps stay free forever.
  29. Narrator: Curriculum aligned to Computer Science Teachers Association standards.
  30. Narrator: Released under Creative Commons BY-NC-SA 4.0. Full transcript at sparkanvil.org slash cast slash coderealm.

More stories with Fork

Another short audio story about Fork. Open one when you are ready.

Conditional branching

Loading audio…

Read the script
  1. Narrator: From Spark and Anvil and CodeRealm — this is Fork, in chapter 1 of the CodeRealm cast.
  2. Narrator: This drama uses an AI-generated voice. Voiced via Gemini 2.5.
  3. Narrator: Fork is a small wooden figure, no taller than a soda can. It is a painted path that splits in two.
  4. Narrator: Above the split, a transparent diamond shimmers. Two arrows point away from it, down two different paths.
  5. Fork: I am Fork. I am not a decision-maker. I am a branch-point for a journey.
  6. Narrator: Fork is a conditional. A program's journey changes direction based on what is true right now.
  7. Fork: A piece of data enters my diamond. Inside, there is a question—a condition to be checked.
  8. Fork: Is the light on? Is the number greater than ten? If true, go left. If false, go right.
  9. Narrator: Fork was carved from a single branch that grew perfectly split, as if it had already made a choice.
  10. Narrator: It arrived at the CodeRealm academy as a simple, unpainted block of wood.
  11. Loop: What is a conditional?
  12. Fork: I am the choice. One question, two paths. The journey depends entirely on the answer.
  13. Loop: You are appointed.
  14. Narrator: One question. Two paths. That is the whole branch. That is what makes a fork a fork.
  15. Narrator: You've been listening to a Spark and Anvil chapter, written by the Spark and Anvil writing team for ages 9 to 14.
  16. Narrator: Apps stay free forever.
  17. Narrator: Curriculum aligned to Computer Science Teachers Association standards.
  18. Narrator: Released under Creative Commons BY-NC-SA 4.0 for educational reuse. Visit Spark and Anvil for the full transcript.

The CodeRealm ensemble

Fork is one of the friends in CodeRealm. Each friend shows you one idea by how they act; meet them all and you have the whole subject.

Kids also liked