1 00:00:00,360 --> 00:00:07,980 Welcome to a very, very important topic, which is the if else topic, i.e. conditional statements, 2 00:00:08,010 --> 00:00:12,360 are we doing something based on a condition that we are testing for? 3 00:00:13,310 --> 00:00:19,350 So let's begin let's say we have a VAR temperature is equal to 12 degrees that Celsius for all the Americans 4 00:00:19,350 --> 00:00:19,690 out there. 5 00:00:20,580 --> 00:00:21,960 I don't know what that is in Fahrenheit. 6 00:00:22,320 --> 00:00:27,930 No idea how to do the conversion, although we will have an idea how to how to do the conversion. 7 00:00:28,170 --> 00:00:33,570 If you're also taking my iOS development course, because we make a temperature converter app there, 8 00:00:33,570 --> 00:00:35,620 so you'll find out the answer there. 9 00:00:37,020 --> 00:00:43,140 What if I want to advise someone as to the clothing they should be wearing based on the outside temperature? 10 00:00:43,620 --> 00:00:49,320 So you might imagine this would be part of a weather app telling you what kind of clothing today is 11 00:00:49,320 --> 00:00:50,710 likely to require. 12 00:00:51,630 --> 00:00:57,120 We would say if the temperature is less than, let's say, perhaps five degrees. 13 00:00:59,310 --> 00:01:00,240 Then we'll print. 14 00:01:03,000 --> 00:01:04,130 Wear a big coat. 15 00:01:06,000 --> 00:01:12,480 It reminds me of a joke that runs between the north and south of the U.K., I currently live in Liverpool 16 00:01:13,740 --> 00:01:18,390 in the south, there's a weather report saying there are terrible storms tomorrow, awful rain. 17 00:01:18,690 --> 00:01:20,190 It's going to be freezing cold. 18 00:01:20,190 --> 00:01:22,280 We advise everyone to stay at home. 19 00:01:22,290 --> 00:01:25,590 Schools are closed and in the north exactly the same way. 20 00:01:25,590 --> 00:01:28,950 The report says you better take your big coat out tomorrow. 21 00:01:32,730 --> 00:01:36,660 That actually sums up the difference between the north and the south of England very, very well. 22 00:01:37,020 --> 00:01:41,700 It's a very interesting difference in the way that people look at life in the north and south. 23 00:01:42,780 --> 00:01:47,920 And I think in America, correct me if I'm wrong, it's the same difference between the northern or 24 00:01:47,920 --> 00:01:50,940 the maybe the coastal states and the interior states. 25 00:01:51,450 --> 00:01:56,850 Am I right in thinking that you're much more individualistic in the interior states versus the coastal 26 00:01:56,850 --> 00:01:57,150 ones? 27 00:01:57,900 --> 00:01:58,560 I could be wrong. 28 00:01:58,710 --> 00:01:59,400 Go ahead. 29 00:01:59,400 --> 00:02:01,740 Feel free to comment if I'm wrong. 30 00:02:01,980 --> 00:02:04,460 Anyway, let's get back to programming now. 31 00:02:04,470 --> 00:02:09,000 The beautiful thing of an if statement is we can have various conditions that we check through. 32 00:02:09,030 --> 00:02:15,000 So if something isn't true, there clearly were not below five degrees, then we want to check for something 33 00:02:15,000 --> 00:02:16,980 else else if the temperature. 34 00:02:18,190 --> 00:02:22,990 Is less than 15 degrees, we might say, Prince. 35 00:02:24,400 --> 00:02:25,830 Bring a jumper. 36 00:02:30,820 --> 00:02:39,130 Which is a jersey or sweat pants or whatever you want to call it in America, and then if we're anything 37 00:02:39,130 --> 00:02:41,260 over 15 degrees or else. 38 00:02:46,570 --> 00:02:48,250 It's T-shirt time. 39 00:02:51,700 --> 00:02:59,260 OK, so running through this, we go through conditions if we have an else, if right, so if it isn't 40 00:02:59,260 --> 00:03:02,650 caught here, it's going to fall through to here. 41 00:03:02,980 --> 00:03:08,360 If that isn't caught, it's going to fall through to as many else if statements as you like. 42 00:03:09,220 --> 00:03:15,400 Finally, if it gets through nothing and nothing matches, it can fall through to the statement which 43 00:03:15,400 --> 00:03:17,680 covers everything else. 44 00:03:18,380 --> 00:03:23,380 OK, now you don't have to have an EL statement, you don't have to have an IF statement. 45 00:03:23,380 --> 00:03:27,040 You can end the whole thing on just a single if statement. 46 00:03:27,370 --> 00:03:31,690 You can have any mix and match of these as long as you always start with an F. 47 00:03:33,320 --> 00:03:38,180 Now, if we run this, we should get bring a jumper and of course, if we increase the temperature to 48 00:03:38,180 --> 00:03:38,690 50. 49 00:03:39,670 --> 00:03:40,380 That's pretty hot. 50 00:03:42,290 --> 00:03:43,160 Wear a big coat. 51 00:03:43,700 --> 00:03:46,680 Ah, I've changed the wrong thing, haven't I? 52 00:03:47,090 --> 00:03:50,270 I've changed that to five waps. 53 00:03:51,050 --> 00:03:52,800 We should be changing this upper temperature. 54 00:03:53,090 --> 00:03:54,320 Let's change that to twenty three. 55 00:03:57,480 --> 00:03:59,150 It's T-shirt time, right? 56 00:03:59,280 --> 00:04:04,890 So that's the if else you're going to use this everywhere, absolutely everywhere. 57 00:04:05,900 --> 00:04:11,660 And so to set you on your way, we're going to have some homework create and if else, statement to 58 00:04:11,660 --> 00:04:16,930 call someone young, middle aged or old based on an age variable. 59 00:04:17,450 --> 00:04:18,350 Pretty straightforward. 60 00:04:18,530 --> 00:04:19,040 Good luck.