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.

Think of it as the "otherwise" part of a decision.

Engagement Message

Make sense?

Section 3 - Instruction

The else statement always follows an if block. It has its own block of code wrapped in curly braces {}. 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