Nested control statements
In the last chapter, we briefly looked at nested control statements. We had a CASE
conditional with an IF
statement inside it. When one control statement is nested inside another, they are typically referred to as either nested or embedded IF
or CASE
statements. A simple example of a nested IF
statement is the beer and money analogy from before. Consider the following pseudocode:
Input age Input money If age >= 21 then If money >= 45 then Let them drink
For this example, two conditions must be true. First, the age of the person must be at least 21 years old. If so, they can move to the next conditional, which checks the amount of money they have. If they have at least $45, they can drink the beer. If any one of these conditionals is false, nothing will happen. In other words, they will not be able to drink! An easy way to think of these conditionals is as gatekeepers...