Page 90 - 2502_Pakistan-kifayat_C-7
P. 90
Indented statement block
# if block ends here
Example 1: To check eligibility to vote
Read age
if age >= 18
print "You are eligible to vote"
Example 2: If there is a rain, carry an umbrella
Read Rain
if Rain = True
print "Carry an umbrella"
The if-then-else Statement
The program executes the statements written inside the if block when the condition is True. If the
condition is False, the statements written inside the else block will be executed. A block refers to a
section of code that is grouped together.
Syntax:
Start
if (Test Expression) then
Indented block
if condition to
be checked
else True False
Indented block
Statements inside if Statements inside else
Example 1: To check whether the period is block execute block will execute
of maths
Read Subject Stop
if Subject = "Maths" then
print "Take out Maths book & notebook"
else
print "Check timetable"
Example 2: To check whether you are pass or fail
Read marks
if marks > 50 then
print "Pass"
else
print "Fail"
88 Premium Edition-VII

