More Complex Logical Expressions

Using the basic logical operators, you can build up more complex expressions.
1
bool travel = haveVacHours && (haveMoney || (canGetLoan && !tonsOfDebt));
The above expression could be read as “I will travel if I have the vacation hours and I either have money on hand or I can take out a loan and don’t already have massive debt”.


Parentheses are used to indicate precedence–i.e. which sub-expressions should be evaluated first.  In the above example, the order of evaluation is: rightmost &&, then ||, then leftmost &&.