
The if-else Statement 167
5.4 THE if-else STATEMENT
In the if–else statement, if the expression/condition is true, the body of the if statement is
executed; otherwise, the body of the else statement is executed. The else keyword is used
when the expression is not true. The format/syntax of
if–else statement is given in Figures 5.5, 5.6 and
5.7.
As shown in Figure 5.7, both if and else blocks con-
tain statement/statements. When the expression is true,
the if block is executed, otherwise, the else block
is executed.
Flowchart for if-else is as shown in Figure 5.8.
Test
Expression
?
Block within the if
statement.
False
True
Next statement
Exit
else statement ...