Chaining if-else Statements

This lesson explains how if-else statements can be chained together to achieve more complex coding goals.

The "if, else if, else" chain #

One of the powers of statements and expressions is the ability to use them in more complex ways. In addition to expressions, scopes can contain other statements. For example, an else scope can contain an if statement. Connecting statements and expressions in different ways allow us to make programs behave intelligently according to their purposes.

Example #

The following is a bit of complex code written under the agreement that riding to a good coffee shop is preferred over walking to a bad one:

Get hands-on with 1200+ tech skills courses.