Guide

Step By Step

The IF conditional

Making Choices

You remember the Boolean type?

It turns out that is very useful to make choices.

This choices inside the program allows us to control our program in spite of different conditions that may happen.

If

The Basic IF structure is a statement that executes when a condition is true.

The meaning is just like when we say in real life "If I want a burger, then is Burger Time!".

I'm hungry at the moment, ok? And I feel like a Burger. You know what that means!

If Statement structure

Ok, I'm back. It was delicious.

Did you try changing True to False? Did anything happen?

If-Else

When we want to provide an alternative, that is, tell the program what to do if the condition is False, then we have to use a if-else structure.

As an example, it would be nice to have a healthy alternative when I don't feel like having a burger. A salad would be nice.

If Else Statement structure

If-Elsif-Else

We can extend the structure to check other conditions afterwards.

We use the code word elsif.

Notice that to check the condition, all previous conditions must be false.

We can write as many elsifs as we want.

Elsif Statement structure