We have seen how conditional if statements allow us for test for something in our code.
These tests are evaluated as true or false and are defined by the following operators:
When these conditionals are true, we run the code block defined by the curly brackets, when they are false we skip through ignoring the code in the brackets.
These if statements can be combined using an else or an else if, as shown below. (Image is from Reas and Fry textbook, chapter 5, control 1)
Logical operators are used to combine two or more relational expressions and to invert logical values. They allow for more than one condition to be considered simultaneously. The logical operators are symbols for the logical concepts of AND, OR, and NOT:
These are all the possible combinations and results:
1. Using mouseX and mouseY, and fill() create a roll-over rectangle that changes color when the mouse is hovering over it.
2. Duplicate your rectangle sketch so that it only changes color when the mouse is hovering over it and is pressed.