So far we've looked at simple if/else statements that we used to control whether code is executed or not based on some basic issues about the state of the world (e.g., the distance between two objects).
In this module we will look at situations where we want to execute some code based on a combination of checks of state in the world -- compound Boolean expressions. Compound expressions are made up of more than one part.
For example, you should only cross the street if there are no cars coming from the left AND no cars coming from the right. That is a compound expression made up of two Boolean situations. Both Boolean situations need to be true for it to be safe for you to cross. Another example could be based on any one of a set of things being true. It's OK to start my homework if I have a pencil OR if I have a pen -- either one (or both would be OK). But if I don't have either, I can't start.
We will learn two different ways that we can handle complex conditions under which we want to execute code -- using compound Boolean expressions and by "nesting" if/else statements (or putting one inside the other).
Things you will learn in this module:
Vocabulary for this module:
both/and operator: A mathematical operator (like "+" or "/") that operates on two Boolean values. If both values are true, then the expression is true. If either one or both of the values are false, then the expression is false.
Compound Boolean Expression: An expression which evaluates to true or false which is made up of multiple Boolean expressions combined with and and/or or.
Nested if/else statements: When one if/else statement has inside either it's "true" section of code or it's "else/false" section of code another if/else statement that enables another condition to be checked to control execution.
either/or/orBoth operator: A mathematical operator (like "+" or "/") that operates on two Boolean values. If either one of the values OR both values are true, then the expression is true. If both of the values are false, then the expression is false.