Booleans and IFs Flashcards
What are the different types of control structures?
Sequences, Choice, and Repetition
What is a boolean
Used for true/false values
What is a boolean expression?
A boolean variable, or an expression that gives a boolean result
What are the built-in boolean values that respond to user input?
mousePressed and keyPressed
How can you invert booleans?
With an exclamation point
What are relational operators?
==, <, <=, !=, >, >=
What are boolean operators?
&&, ||, !
What is the order of operations now?
- expressions in parentheses
- Unary operators: +, -, ++, –, !
- Multiplicative: * / %
- Additive: +, -
- Relational: >, <, >=, <=
- Equality: ==, !=
- Logical and: &&
- Logical or: ||
- Assignment: =, +=, -=, *=, /=, %=
What is short-circuiting?
If a condition is met, no further conditions will be tested in the if-else-if chain, or a test will be stopped as soon as the answer is known
Why is it sometimes difficult to tell if two floating-point numbers are equal?
Because they are approximations. Errors accumulate as you do operations, so it is better to use >= and\or <= instead