In the last module, we adjusted our behavior according to the state of the world. For example, the Angel always moved toward the Egyptian when the Enter key was pressed, but distance of this movement depended on the particular positions of both Egyptian and Angel at the time the key was pressed, and these could be changed as the program was running (that is we changed how far the Egyptian was from the Angel by pressing arrow keys to move him around). We used functions to calculate how far to move. No matter the distance, the Angel always moved the appropriate, calculated distance.
In this module we are going to take this concept a step further. Depending on the state of the world the program will perform completely different actions.
A real world example of completely different things happening depending on the state of some specific thing is "If there is more than 2 gallons of gas in the tank, then drive car to work, otherwise take the bus." The state our action depends on is the amount of gas in the car's tank. There are two possible actions (driving the car and taking the bus) - but at any time only ONE of them will happen. We select what to do depending on whether there is more than 2 gallons of gas in the tank or not. In computing speak, we would say the following: "If we have more than two gallons gas in the tank then we should drive the car, else (meaning otherwise) we should take the bus."
Things you will learn in this module:
Vocabulary for this module:
Conditional Expression: Conditional Expressions are another name for If/Else statements. These expressions evaluate a function (for instance -- equal to, greater than, less than, etc.) and depending on the result, perform a certain action. That is, they perform an action on the condition to determine if it is "true".
Conditional Execution: Conditional Execution is a term that describes actions resulting from Conditional Expressions. Based on the conditional expression, one piece of code is executed, another is not.
If/Else: The If/Else tile is Alice's version of Conditional Expressions. These green colored tiles say: If something, then do A. Else (otherwise), do B.
Boolean Operators: Boolean operators are terms that are used to logically evaluate statements. Alice uses the Boolean operators And, Or, and Not. Boolean operators return a value of either "true" or "false".