Welcome to a very, very important topic, which is the if else topic, i.e. conditional statements,
are we doing something based on a condition that we are testing for?
So let's begin let's say we have a VAR temperature is equal to 12 degrees that Celsius for all the Americans
out there.
I don't know what that is in Fahrenheit.
No idea how to do the conversion, although we will have an idea how to how to do the conversion.
If you're also taking my iOS development course, because we make a temperature converter app there,
so you'll find out the answer there.
What if I want to advise someone as to the clothing they should be wearing based on the outside temperature?
So you might imagine this would be part of a weather app telling you what kind of clothing today is
likely to require.
We would say if the temperature is less than, let's say, perhaps five degrees.
Then we'll print.
Wear a big coat.
It reminds me of a joke that runs between the north and south of the U.K., I currently live in Liverpool
in the south, there's a weather report saying there are terrible storms tomorrow, awful rain.
It's going to be freezing cold.
We advise everyone to stay at home.
Schools are closed and in the north exactly the same way.
The report says you better take your big coat out tomorrow.
That actually sums up the difference between the north and the south of England very, very well.
It's a very interesting difference in the way that people look at life in the north and south.
And I think in America, correct me if I'm wrong, it's the same difference between the northern or
the maybe the coastal states and the interior states.
Am I right in thinking that you're much more individualistic in the interior states versus the coastal
ones?
I could be wrong.
Go ahead.
Feel free to comment if I'm wrong.
Anyway, let's get back to programming now.
The beautiful thing of an if statement is we can have various conditions that we check through.
So if something isn't true, there clearly were not below five degrees, then we want to check for something
else else if the temperature.
Is less than 15 degrees, we might say, Prince.
Bring a jumper.
Which is a jersey or sweat pants or whatever you want to call it in America, and then if we're anything
over 15 degrees or else.
It's T-shirt time.
OK, so running through this, we go through conditions if we have an else, if right, so if it isn't
caught here, it's going to fall through to here.
If that isn't caught, it's going to fall through to as many else if statements as you like.
Finally, if it gets through nothing and nothing matches, it can fall through to the statement which
covers everything else.
OK, now you don't have to have an EL statement, you don't have to have an IF statement.
You can end the whole thing on just a single if statement.
You can have any mix and match of these as long as you always start with an F.
Now, if we run this, we should get bring a jumper and of course, if we increase the temperature to
50.
That's pretty hot.
Wear a big coat.
Ah, I've changed the wrong thing, haven't I?
I've changed that to five waps.
We should be changing this upper temperature.
Let's change that to twenty three.
It's T-shirt time, right?
So that's the if else you're going to use this everywhere, absolutely everywhere.
And so to set you on your way, we're going to have some homework create and if else, statement to
call someone young, middle aged or old based on an age variable.
Pretty straightforward.
Good luck.