About Lesson
The if-else statement is used to make a decision regarding which code path to take based on a condition. The syntax looks like this:
if (expression) statement1 else statement2
If the expression after evaluation yields a non-zero value (true), then statement1 is executed. If it yields zero (false), then statement2 is executed (if there is an else part).
In case of nested if statements, else is associated with the closest previous else-less if. For example:
if (a > b) if (a > c) z = a; else z = c;
In the above snippet, else goes with the inner if (as indicated by the indentation). If that is not the case, we must use braces as shown below:
if (a > b) { if (a > c) z = a; } else z = b;