✦ ✦
Computer Science · Coding Basics

Conditionals and Boolean Logic

A conditional tests a condition and runs the instructions for the matching branch.
🍴Following a branch
Is the condition true? TRUE ✔ IF: true branch run this code 🟢 FALSE ✘ ELSE: false branch run other code 🔴
🎮Read the Code: a Lava Game
game.code
# test for contact with lava
IF player touches lava:
lose a life  💔
ELSE:
keep running 🏃
🔢True or False? (Boolean Logic)
TRUE ✔
the condition is met
FALSE ✘
the condition is not met
<
less than
>
greater than
==
is equal to
!=
not equal to
≤
less or equal
≥
greater or equal
AND
TRUE only when BOTH are true.
green light AND no cars
OR
TRUE if at least one is true.
snack OR juice
NOT
Reverses the result. True becomes false.
NOT raining = not raining
🚦A crosswalk example
WALK
Check the pedestrian signal and look for traffic, including turning vehicles.
✔IF the Walk signal is on and the way is clear → CROSS 🚶
✘ELSE → WAIT at the curb
🔑Key Terms
🔀Conditional Code that branches based on a true/false test.
⚖️Boolean A value that is only TRUE or FALSE.
✅IF Statement A statement that tests a condition. Its selected branch runs when the condition is true.
↩️ELSE Statement An optional branch that runs when none of the preceding if or else-if tests is true.
➗Comparison Operator A symbol that compares values: < > == != ≤ ≥.
🔗AND · OR · NOT Logic words that combine or flip true/false tests.
⭐ In the lava game, touching lava takes one branch. Trace the other branch when the player stays on the path.
✏️ Computer Science Anchor Chart · Conditionals: Making Decisions
ClickClass offers hundreds of free printables at clickclassedu.com/printables.