The if-else Statement

In this lesson, we will use the if-else statement to choose between two courses of action.

What is an if-else statement?

So far, we have used the if statement to do something if a certain condition is true, but to not do it if the condition is false. Frequently, however, you want to do one thing if a certain condition is true and another thing if it is not, as the figure given below illustrates.

Get hands-on with 1200+ tech skills courses.