AS your applications become more complicated, you can expect your decisions to become more complicated. There are three ways this can happen.
First, is a sequence of conditions, checking against the same variable. So in our last decision example, we mentioned how we cannot ask “What color is the shirt?” However, we might ask: “Is the Shirt Red” then if not, “Is the Shirt Blue” then if not, “Is the Shirt Green”, and on and on we could test for a large number of values to get the shirt’s color and do something based upon the result.
In some languages, like C/C++ and Java, we have a switch statement that lets us do this. In flowcharts it will just be a series of conditional statements.
However, these are basically the same as before, so were not going to walk through that example. Instead we want to see examples of the other two types of more complex decisions.
Nested Conditional Statements
Nested conditions is when you have one conditional statement inside the true, or false, block of another statement. If it is in a true block, that means that your are typically looking for both conditions to be true. Of course it can be different depending upon your needs.
There is no limit as to how many levels of nesting you have, although no nesting is the most popular, then followed by one level of nesting and two. Rarely do you need more than two levels of nesting.
Boolean Operators in Conditional Statements
This is the third type of more complex conditional statement. This is helpful for simplifying some types of nested conditions or sequential statements.
Boolean AND
With a Boolean AND, both conditions must be met in order for the whole thing to be true. We typically write this as AND, although some languages will use a different nomenclature, such as &&, or all lowercase.
For example, let’s say you want to buy a car, but to qualify for the loan, you must have a job, and your credit score must be a 625 or higher. Then you can write a conditional statement using the Boolean AND operator, which looks like : haveJob == ‘y’ AND creditScore >= 625
Boolean OR
With a Boolean Or, you are only looking for one or the other to be true – although both can be true as well. For example, you might get a discount at a store if the manager approves it, OR you have a coupon. It doesn’t matter if you have both, only one is necessary. To write it, it might look like coupon == ‘y’ OR managerApproval == ‘y’
Visual Example of Boolean Operators in a Flowchart
More Advanced Conditional Statements was originally found on Access 2 Learn