Mapa mental
Decision Statements
Conteúdo do mapa
Decision Statements
If statements: checks if the condition given is true. If true, then it will execute the code embeded in it.
- Brackets vs. Dangling: In order to have multiple operations occur, you must have brackets. If you only need one line, then you can just put it under the condition, also known as dangling
Comparing values
- For number types, you can use the "==" operator
- For objects and strings, you must use the "compareTo" method
Boolean expressions: determines if true or false
- ||(or) returns true if at least one condition is true
- &&(and): returns true if both conditions are true
- !(not): returns true if condition is false.
- Demorgans law: !(a || b) is the same as (!a && !b); and !(a && b) is the same as (!a || !b)
- Short circuit: When java finds one side of an && to be false; or finds one side of || to be true; it will return false/true without checking the other side.
Common mistakes
- x > 0 && x < 100; not 0 < x < 100
- color == "green" || color == "blue"; not color == "green" || "blue"
- Use compareTo with strings and objects instead of the "==" operator
- null is not the same as an empty string
- do not put a semicolon at the end of an if statement
Informações
- Descrição
- Mapa Mental sobre Decision Statements, criado por John Hair em 26-04-2018.
- Criado por
- John Hair
- Visualizações
- 1
- Avaliação