Page 56 - ThinkGPT_V2.1_C8_Flipbook
P. 56
Multiple Conditions in a Program Start
Conditional statements are used in a program to
instruct the computer to make a decision. The
if False
result of the condition will always be either true
condition
or false. The program executes the statements
written after ‘if’ when the condition is true. If it
True
is false, the statements written after ‘else’ will be
Statement inside if Statement inside else
executed.
block will execute block will execute
But there might be situations when we need to
check for multiple conditions in a program. For
example, look at these programs: Stop
username = "Orange"
password = "secure123"
IF username = "Orange" AND password = "secure123" THEN
PRINT "Access granted"
ELSE
Access granted
PRINT "Access denied"
user_type = "member"
coupon_value = "invalid"
IF user_type = "member" OR coupon_value = "valid" THEN
PRINT "Eligible for discount"
ELSE
Eligible for discount
PRINT "Not eligible for discount"
What did you notice?
Both the programs have two IF conditions joined Just as plants need sunlight to
together using AND or OR. The final result depends on produce glucose, algorithms need
the combined result. right data to generate optimum
results.
AND: results in true only if both the conditions are
true. If any one condition is false, the result will be
false.
OR: results in true if any one of the conditions is true. If both are false, the result will be false.
Now, write your answers for both.
1. age =20 2. shop = 500
customer = "new"
IF age >= 12 AND age <= 19 THEN
IF shop > 100 OR customer = "old" THEN
PRINT "You are a teenager"
PRINT "Eligible for a free gift"
ELSE ELSE
PRINT "You are not a teenager" PRINT "Not eligible for a free gift
54 Premium Edition-VIII

