# Subgoals

## Section4.12Worked Example: Nested If-Else Statements

### Subgoals for Evaluating Selection Statements.

1. Diagram which statements go together
2. For if statement, determine whether expression is true or false
3. If true ߝ follow true branch, if false ߝ follow else branch or do nothing if no else branch

### Subsection4.12.1

You can watch this video or read through the content below it.
Given the following declarations:
int alpha = 2, beta = 1, delta = 3, eta = 0, gamma = 0;

double omega = 2.5, theta = -1.3, kappa = 3.0, lambda = 0.0, rho = 0.0;

Evaluate these statements and determine the value of all variables used.
if (omega > kappa)
{
if (alpha < delta)
eta = 5;
else
eta = 4;
}
else
if (alpha > delta)
eta = 3;
else
eta = 2;


### Subsection4.12.2SG1: Diagram which statements go together.

In this diagram, the first thing to note is the parent/outer if-else statement highlighted in blue.
The true branch of the parent/outer statment contains an inner if-else.
Likewise, the else branch of the parent/outer statement contains an inner if-else.

### Subsection4.12.3SG2: For if statement, determine whether true or false

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 (omega > kappa):
(2.5 > 3.0) is FALSE

### Subsection4.12.4SG3: If true, follow true branch. If false, follow else branch (OR do nothing if there is no else branch).

The else branch contains another if-else statement, so we must repeat the SG2 and SG3.

### Subsection4.12.5SG2: For if statement, determine whether true or false

(2 > 3) is FALSE