Lesson 5: Conditions (If/Then)
Sometimes we want a computer to make a choice. 'IF it's raining, THEN bring an umbrella.' In coding, we use IF statements to make decisions. The computer checks if something is true — and if it is, it does something special.
Key Concepts
If Statements
'If' statements check a condition. IF the condition is TRUE, the code runs. IF it's FALSE, it skips. Example: IF score > 10, THEN show 'You Win!'
If / Else
You can add an ELSE to give an alternative: IF score > 10, THEN 'You Win!' ELSE 'Keep Trying!' — now the computer has a response for both cases.
Conditions in Games
IF the character touches a wall → stop. IF the timer reaches 0 → game over. IF you collect all coins → next level! Conditions make games feel smart and responsive.
🆕 Activity: Condition Checker
Set the number, then ask the computer to check different conditions. Watch it decide TRUE or FALSE!
✅ Check Your Understanding
1. An IF statement in coding is used for:
2. IF score > 10 THEN 'You Win!' — what runs when score is 6?
3. 'IF it rains THEN bring umbrella ELSE enjoy sunshine' is an example of: