else if statements
A variation of the if
statement is an if
statement with multiple else if
blocks. This can be more efficient in certain situations because you are always only going to execute one or zero blocks. If you have many if else
statements underneath one another, they are going to be evaluated and possibly executed even though one of the ones above already had a condition evaluate to true and proceeded to execute the associated code block.
Here is the written template:
If *a value falls into a certain category*, then *a certain action will happen*, else if *the value falls into a different category than the previous statement*, then *a certain action will happen*, else if *the value falls into a different category than either of the previous brackets*, then *a certain action will happen*
For example, take this statement, to determine what the ticket price should be. If a person is younger than 3, then access is free, else if a person is older than...