Back
🔀Conditionals

If/then logic and decision making

🔀

Conditionals: If/Then Logic

Key Points

  • A CONDITIONAL is an 'IF this is true, THEN do that' rule — the foundation of decision-making in code
  • True or False questions are called BOOLEAN — computers see everything as true or false (1 or 0)
  • IF/ELSE handles both cases: IF raining → take umbrella, ELSE → wear sunglasses
  • You can combine conditions: IF it's raining AND cold THEN wear coat and take umbrella

📘 Examples

IF today is Saturday, THEN no school. What happens if today is Saturday?

No school! The condition 'today is Saturday' is TRUE, so the action ('no school') happens!

IF x > 5 THEN print 'big'. What prints when x = 3?

Nothing! 3 is NOT greater than 5, so the condition is FALSE and nothing prints!

Add an ELSE: IF hungry, eat a snack. ELSE ___

ELSE: don't eat! The ELSE clause handles what happens when the condition is false!

🌟 Fun Fact!

Every 'yes or no' decision inside a computer is made by a tiny switch called a TRANSISTOR. Modern computer chips pack over 50 BILLION transistors into a chip the size of your fingernail! ⚡

A conditional is a decision: if something is true, do this, otherwise do that. It is what allows a program to behave differently depending on circumstances rather than always doing the same thing.

Children use conditionals constantly without naming them. If it is raining, take a coat. Making that structure explicit is most of the teaching.

Ideas to build

  • That a condition is something that is either true or false, with no in-between.
  • That if-then-else covers both outcomes, so the program always knows what to do.
  • That conditions can combine with and and or, which changes when they apply.
  • That the order of conditions matters when more than one could be true.

Things to do at home

  • Play a game where a rule applies conditionally, such as clapping only on even numbers.
  • Write household rules as if-then statements and look for cases they do not cover.
  • Sort objects using a rule with and or or, such as red and round.
  • Find the gap in a rule deliberately, which is how children learn to think about edge cases.

Frequently asked questions

What is a conditional in coding?
An instruction that runs only when a condition is met, usually written as if-then or if-then-else. It is what allows a program to respond differently to different situations.
How do I explain conditionals to a child?
Use everyday rules they already follow, such as if it is raining, take a coat. Writing familiar rules in if-then form makes the structure visible in something they already understand.
What is an else statement?
The alternative branch: what happens when the condition is not true. Including it means the program has a defined action in both cases rather than only one.