Control Structures – Decision
Making in Programming
• Understanding IF, ELSE, and ELSE IF
Statements
Why Do Computers Need
Decisions?
• Computers make decisions like humans (e.g.,
checking passwords, grading systems).
What is an IF Statement?
• IF condition THEN
• Do something
• ENDIF
• Example:
• INPUT temperature
• IF temperature < 15 THEN
• PRINT 'Wear a jacket'
• ENDIF
IF-ELSE Statement
• IF number MOD 2 == 0 THEN
• PRINT 'The number is even'
• ELSE
• PRINT 'The number is odd'
• ENDIF
ELSE IF – Handling Multiple
Conditions
• Example:
• INPUT score
• IF score >= 90 THEN
• PRINT 'Grade: A'
• ELSE IF score >= 75 THEN
• PRINT 'Grade: B'
• ELSE IF score >= 50 THEN
• PRINT 'Grade: C'
• ELSE
Real-World Example – Login
System
• INPUT password
• IF password == 'mypassword' THEN
• PRINT 'Access Granted'
• ELSE
• PRINT 'Access Denied'
• ENDIF
Age-Based Ticket Pricing Example
• INPUT age
• IF age < 12 THEN
• PRINT 'Child Ticket: $5'
• ELSE IF age < 18 THEN
• PRINT 'Teen Ticket: $8'
• ELSE
• PRINT 'Adult Ticket: $12'
• ENDIF
Debugging Challenge – Find the
Mistakes
• Incorrect Code:
• IF age > 18 THEN
• PRINT 'You can vote'
• ELSE IF age < 18 THEN
• PRINT 'You cannot vote'
• ELSE
• PRINT 'Invalid age'
• ENDIF
Group Activity – Traffic Light
System
• INPUT light_color
• IF light_color == 'Red' THEN
• PRINT 'Stop'
• ELSE IF light_color == 'Yellow' THEN
• PRINT 'Slow Down'
• ELSE IF light_color == 'Green' THEN
• PRINT 'Go'
• ELSE
• PRINT 'Invalid color'
Creative Challenge – Temperature-
Based Outfit Selector
• INPUT temperature
• IF temperature < 10 THEN
• PRINT 'Wear a heavy jacket'
• ELSE IF temperature < 20 THEN
• PRINT 'Wear a sweater'
• ELSE
• PRINT 'Wear a T-shirt'
• ENDIF
Summary – What Did We Learn?
• ✔ Computers make decisions using IF
statements.
• ✔ ELSE is used for two choices.
• ✔ ELSE IF helps with multiple choices.
• ✔ Pseudocode helps plan logic before coding.
Final Question – Can You Think Like
a Computer?
• How would a computer decide for:
• - A weather app?
• - A banking system?
• - A game where a player's health is 0?
Thank You! Q&A
• Feel free to ask any questions!