Not only do the values of variables change when a program runs, but the flow of execution can also change through a program. The order of statement execution can be altered depending upon the results of conditional expressions. In a conditional program flow, there is one mandatory branch and one optional branch. If the condition is met, the first branch, or path, will be taken; if not, the second path will be taken.
We can illustrate such a branching with the following simple example:
If so, do the laundry.
Else, go for a walk.
In this conditional statement, we are instructed to do the laundry if today is Saturday. For the remaining days that are not Saturday, we are instructed to go for a walk.
This is a simple conditional statement; it has a single conditional expression, a single mandatory branch, and a single optional branch. We will explore...