Section 1 - Instruction

In our last session, we saw how if statements run code only when a condition is True. Like checking age >= 18 before printing "You can vote!".

But what if the condition is False?

Engagement Message

What should the program do then?

Section 2 - Instruction

Often, we want to provide an alternative action when the if condition isn't met. This is where the else statement comes in handy! It specifies code to run only when the if condition evaluates to False.

Engagement Message

Think of it as the "otherwise" part of a decision. Make sense?

Section 3 - Instruction

The else statement always follows an if block. It has a colon : and its own indented block of code below it. It doesn't need its own condition because it catches everything the if didn't.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal