Logic Statements
Up to this point, our code has been rather static. It will do the same thing every time we execute it. In this chapter, that is all going to change. We will be dealing with logical statements. Logical statements allow us to make multiple paths in our code. Depending on the outcome of a certain expression, we will follow one code path or another.
There are different logic statements, and we will go over them in this chapter. We will start with if
and if else
statements. After that, we will be dealing with the ternary operator, and the final one we will be dealing with is the switch
statement.
Along the way, we will cover the following topics:
- if and if else statements
- else if statements
- Conditional ternary operators
- switch statements
Note: exercise, project and self-check quiz answers can be found in the Appendix.