Section 4.7 Sequential If Statements
Subgoals for Evaluating Selection Statements.
Subsection 4.7.1
Given the following declarations:
alpha = 2
beta = 1
delta = 3
eta = 0
gamma = 0
Evaluate these statements and determine the value of all variables used.

if alpha > beta:
eta = alpha + 2
if alpha > delta:
gamma = alpha + 5
Subsection 4.7.2 1. Diagram which statements go together by indentation
There is a single indented statement in the body of the first
if
statement, and a single indented statement in the body of the second if
statement.
Subsection 4.7.3 2. For conditional, determine whether expression is true
Because there are 2 sequential if-statements, we start with the first one, and then repeat SG2 and SG3 for the other.
First we evaluate alpha > beta:
Subsection 4.7.4 3. If true, follow true branch; If false, follow next elif/else branch or exit conditional if no else branch
The condition is
True
, so we execute the true branch.
eta = alpha + 2
= 2 + 2
= 4

Subsection 4.7.5 SG2: For if statement, determine whether expression is true
Because there are 2 sequential if-statements, we need to repeat SG2 and SG3 for the second if-statement in the sequence.
First we evaluate alpha > delta:
Subsection 4.7.6 SG2.2: If false, follow next elif/else branch or exit conditional if no else branch
The condition is FALSE and there is no else branch, so we do nothing.

Practice Pages.
You have attempted of activities on this page.