Assigning Boolean Values
Boolean values are either true or false.
The IF Statement
An if statement tests if a boolean value or comparison is true.
The ELSE Clause
Adding alternative code to run when the if condition is false.
Formatting an If Statement
If statements are easier to read if you format them consistently.
Multiple Tests – And, Or, and Not
You can combine tests in a single if condition by using the logical operators.
Nesting If Statements
You can nest if statements one inside another in order to test for any combination of conditions you require.
A Shorter IF Statement
We can use the ternary operator to produce shorter if statements when the purpose is to assign one of a range of values into a single variable.
The SWITCH Statement
Where you want to perform different code when a single variable contains different values it is far simpler to use a switch statement.
The DEFAULT Clause
The default clause provides a switch statement with a way of processing all the values not specifically listed.
Combining Case Clauses Together
Where you want the same code to run for multiple values you can combine case clauses together.