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! ⚡