if...else Statements

Let's build upon our concepts of the original if statements with the else statement.

What is an if...else statement?

An if statement can be followed by an optional else statement, which executes when the conditional expression is FALSE.

Let’s revisit our previous example. So now, we not only want to print “positive” when we encounter a positive number, but we also want to print “negative” when the number is not positive.

We have used the word not positive here to show that the else statement is executed whenever the original conditional statement is NOT satisfied.

Have a look at the modified illustration:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy