1 00:00:00,470 --> 00:00:06,500 Welcome back in the last video, we looked at if statements and I wanted to give you another example 2 00:00:06,500 --> 00:00:12,320 of if statements and this time with a different type because we used integers and we compared integers 3 00:00:12,320 --> 00:00:17,990 and you can even see that it says I should change that to a when statement. 4 00:00:17,990 --> 00:00:19,850 So is simplify this expression. 5 00:00:20,480 --> 00:00:26,210 And if I hover over it's a cascade, it should be replaced with when and I told you that we would look 6 00:00:26,210 --> 00:00:30,950 at when expressions in this video, but we're going to do that in the next one because I want to do 7 00:00:31,220 --> 00:00:38,690 a little more on if statements because, for example, I want to create this variable called name and 8 00:00:38,690 --> 00:00:40,340 I'm going to set the value to Dennis. 9 00:00:40,910 --> 00:00:46,070 So now I want to show you how to use if statements with strings and other data types. 10 00:00:46,280 --> 00:00:50,780 So if name is equal, equal Dennis, then. 11 00:00:51,860 --> 00:00:54,560 I want to write something like Welcome Home. 12 00:00:54,890 --> 00:00:56,030 So print line. 13 00:00:57,110 --> 00:00:59,030 Welcome home, Dennis. 14 00:01:00,020 --> 00:01:00,410 All right. 15 00:01:00,830 --> 00:01:07,070 But else I want to say, who are you, for example? 16 00:01:07,800 --> 00:01:12,770 OK, so this is something that we can also do, so we can check strings as well. 17 00:01:12,950 --> 00:01:19,340 What's important is that whatever is within those brackets can be either true or false. 18 00:01:19,460 --> 00:01:26,510 So it has to be a Boolean that will be the result of whatever is within the brackets. 19 00:01:27,800 --> 00:01:36,920 So the simplest form would be we have a variable here is rainy is true, for example. 20 00:01:36,950 --> 00:01:46,700 So now it's raining and now I can check if it is rainy is true, then do some cold so print and it's 21 00:01:47,540 --> 00:01:50,360 rainy, even though here of course, it's complaining. 22 00:01:50,360 --> 00:01:53,000 Or it says the condition is always true. 23 00:01:53,000 --> 00:01:56,540 So is rain will always be true because it's a vowel, so it can never be changed. 24 00:01:56,910 --> 00:02:00,050 We changed it to Avar than it at least can be changed. 25 00:02:00,050 --> 00:02:06,770 So now this warning is not there anymore, but you can see this is another way of doing if statement. 26 00:02:06,770 --> 00:02:11,150 So the important part is that whatever is within the brackets can be either true or false. 27 00:02:11,750 --> 00:02:13,580 So is a Boolean in the end. 28 00:02:15,630 --> 00:02:21,720 Another important aspect of if statements that I haven't covered yet is the following if we look at 29 00:02:21,720 --> 00:02:28,120 this if statement here, we can see that it says age greater equal to one. 30 00:02:28,140 --> 00:02:30,750 And here it says age greater equal 18. 31 00:02:31,260 --> 00:02:38,550 So this statement is true if that statement is also true, or let's say this statement here is true 32 00:02:38,850 --> 00:02:40,320 if that statement here is true. 33 00:02:40,740 --> 00:02:48,090 So what this means is that even though the statements on their are also true, we first of all, look 34 00:02:48,090 --> 00:02:48,870 at the first one. 35 00:02:49,050 --> 00:02:52,710 And if that one is true, then we ignore all the other ones. 36 00:02:53,010 --> 00:02:59,490 That is something very important about if statements, because they always only look at the first expression. 37 00:02:59,490 --> 00:03:04,560 If it's true and if it's not true, then it starts to look at the next expression. 38 00:03:04,890 --> 00:03:06,450 Then at the next one. 39 00:03:06,750 --> 00:03:11,010 And if none of the expressions are true, then the ALS blog is executed. 40 00:03:11,610 --> 00:03:18,660 So it's not like all of them will be executed if the age is greater than 16, because all those three 41 00:03:18,660 --> 00:03:19,710 would be true, right? 42 00:03:20,160 --> 00:03:24,030 But only the first one, and that is generally true for if statements. 43 00:03:24,030 --> 00:03:29,670 So it always goes top to bottom, which means first line to the last line of this statement. 44 00:03:29,910 --> 00:03:31,750 And this is a whole if statement blocks. 45 00:03:31,750 --> 00:03:38,430 So they're all interconnected to each other, which means that this ALS block really depends on all 46 00:03:38,430 --> 00:03:39,120 of the other. 47 00:03:39,150 --> 00:03:42,000 If an 11 blocks to be false. 48 00:03:42,450 --> 00:03:44,160 Otherwise, it will never be executed. 49 00:03:45,120 --> 00:03:51,170 All right, so I'd say let's go to when expressions and see how they are different too, if statements, 50 00:03:51,170 --> 00:03:52,320 so see you in the next video.