1 00:00:12,370 --> 00:00:13,300 Hello and welcome. 2 00:00:13,330 --> 00:00:18,550 Today, we will kick off with a new topic, which will be if conditions, statements, if conditions 3 00:00:18,550 --> 00:00:27,040 is a meaningful part in programming in general and in Python specifically, if conditions have strong 4 00:00:27,040 --> 00:00:30,160 connections also to the next topic, which will be Loop's. 5 00:00:30,610 --> 00:00:35,620 And let's go straight ahead for the theoretical part definition. 6 00:00:36,130 --> 00:00:41,470 So if is if condition is an ability for decision making. 7 00:00:41,980 --> 00:00:47,620 In other words, sometimes in our call we would like to take a certain variable or a certain collection 8 00:00:47,890 --> 00:00:57,040 and decide what happens if the value that we are dealing with will be will be equals for something or 9 00:00:57,040 --> 00:00:58,810 it will be bigger than something. 10 00:00:59,080 --> 00:01:05,800 And what will happen if our if condition, meaning our question will be true, then we would submit 11 00:01:05,800 --> 00:01:07,240 a certain part of the code. 12 00:01:07,450 --> 00:01:12,740 And if the result will be false, we would like a different code to run. 13 00:01:13,390 --> 00:01:16,210 So this is decision making in summary. 14 00:01:16,540 --> 00:01:23,140 So if condition is an ability for decision making and for that if conditional statement was created, 15 00:01:23,440 --> 00:01:31,090 also known as if else statement, meaning if you encounter this term, so this term and if conditions 16 00:01:31,090 --> 00:01:31,670 is the same. 17 00:01:32,410 --> 00:01:39,790 So in computer science and if statement gives it an ability, the ability to execute a bulk of code 18 00:01:39,790 --> 00:01:45,680 for a choice for your choice, only if a certain condition is satisfied. 19 00:01:46,000 --> 00:01:55,210 This happens as the result of an if statement is a true or false boolean value, meaning the output 20 00:01:55,210 --> 00:02:00,040 of an condition could be only two options, true or false. 21 00:02:00,220 --> 00:02:06,790 And then we can decide what happens if the value of the if condition is true and what will happen if 22 00:02:06,790 --> 00:02:07,450 it's false. 23 00:02:08,020 --> 00:02:13,930 So let's start off with a simple syntax example here. 24 00:02:13,930 --> 00:02:17,480 We can see and if conditional example or this part right here. 25 00:02:17,770 --> 00:02:23,830 So first of all, we're defining here a variable X and it's equal to three. 26 00:02:24,100 --> 00:02:27,910 And then we're asking the if condition right here. 27 00:02:28,120 --> 00:02:32,240 It's right in here if X is larger than four. 28 00:02:32,590 --> 00:02:40,780 So if you'd like to cast it, as you might say, to human language, this is a question. 29 00:02:41,080 --> 00:02:49,720 This is a question we're asking is if bigger than for it's a question and if the answer is true. 30 00:02:50,230 --> 00:02:52,310 So you can see an indent right here. 31 00:02:52,610 --> 00:02:58,960 This is the intent of the if so if the output here is true, boolean boolean value true. 32 00:02:59,260 --> 00:03:02,830 So please print out this bulk of code. 33 00:03:03,610 --> 00:03:12,010 And if it's false, then the code flow will go straight ahead to the else part and it will print the 34 00:03:12,010 --> 00:03:12,520 value. 35 00:03:12,550 --> 00:03:14,290 No, it's very simple. 36 00:03:14,440 --> 00:03:14,800 All right. 37 00:03:15,050 --> 00:03:17,550 So it's a question if the answer is yes. 38 00:03:17,560 --> 00:03:22,150 So print this one if the answer is true, to be more accurate. 39 00:03:22,180 --> 00:03:29,290 So print this bulk of code and if it's false, then go get out of the F and go to what you have in the 40 00:03:29,290 --> 00:03:29,700 else. 41 00:03:29,950 --> 00:03:37,810 This is like the default exit point, meaning if this value ratio is false, meaning if the value right 42 00:03:37,810 --> 00:03:44,950 here is false, then go to the default exit point, which will be the errors and run what you have under 43 00:03:44,980 --> 00:03:45,670 the else. 44 00:03:46,960 --> 00:03:48,970 So this is a quick brief. 45 00:03:49,310 --> 00:03:49,640 All right. 46 00:03:49,810 --> 00:03:50,440 Right here. 47 00:03:50,440 --> 00:03:51,490 Let me just fix it. 48 00:03:52,490 --> 00:04:00,200 This and this, yeah, so let's I'm going to repeat several times on what we just discussed right there, 49 00:04:00,200 --> 00:04:04,340 one of the ones of you that got the hang of it, just go and play. 50 00:04:04,340 --> 00:04:06,980 Fast forward the following minute. 51 00:04:07,190 --> 00:04:13,490 But for those of you who have trouble to get the concept, I'm going to repeat it several times so we'd 52 00:04:13,490 --> 00:04:16,670 go deeper into your DNA. 53 00:04:16,730 --> 00:04:17,060 All right. 54 00:04:17,570 --> 00:04:19,160 So follow steps. 55 00:04:19,160 --> 00:04:23,930 So we have here also a sketch of the flow, the call flow. 56 00:04:23,970 --> 00:04:25,200 So what happens here? 57 00:04:25,220 --> 00:04:27,120 Basically, I'm explaining what happened here. 58 00:04:27,140 --> 00:04:27,440 All right. 59 00:04:27,770 --> 00:04:34,250 So first of all, we start the program, we start the class, we run the class that this bulk of code 60 00:04:34,250 --> 00:04:34,840 is in it. 61 00:04:34,850 --> 00:04:35,720 So we started. 62 00:04:36,080 --> 00:04:39,050 Then we encounter and if condition. 63 00:04:39,050 --> 00:04:39,270 Right. 64 00:04:39,290 --> 00:04:42,160 This is the yellow part right here. 65 00:04:43,010 --> 00:04:52,390 And then there is a question in the if condition if the answer is to run the code back inside the if 66 00:04:52,400 --> 00:04:53,090 meaning. 67 00:04:53,270 --> 00:04:54,460 Meaning print. 68 00:04:54,470 --> 00:04:54,980 Yes. 69 00:04:55,290 --> 00:04:59,930 And if the answer is false, then run the code back inside or else. 70 00:05:00,410 --> 00:05:00,820 All right. 71 00:05:01,190 --> 00:05:03,790 So you have the same explanation right here. 72 00:05:05,270 --> 00:05:07,820 So what actually like what? 73 00:05:07,820 --> 00:05:10,330 Like physically will be the output of this one. 74 00:05:10,520 --> 00:05:18,710 So we declared here X equals three, then we ask X bigger than for obviously the output of this one 75 00:05:18,710 --> 00:05:19,270 is false. 76 00:05:19,430 --> 00:05:26,180 So the output of this whole F condition would be print will get the output. 77 00:05:26,180 --> 00:05:26,640 No. 78 00:05:26,960 --> 00:05:27,410 All right. 79 00:05:29,070 --> 00:05:38,250 All right, so in this case, Perrino will be executed as the condition we have, it's bigger than four 80 00:05:38,460 --> 00:05:39,390 is false. 81 00:05:39,600 --> 00:05:47,690 So the court under house will run because house is used as a default exit point for the state for if 82 00:05:47,700 --> 00:05:48,960 the statement is not true. 83 00:05:49,650 --> 00:05:50,650 Pretty easy, right? 84 00:05:50,670 --> 00:05:52,560 We have just two options here. 85 00:05:52,830 --> 00:05:54,280 This or this. 86 00:05:54,840 --> 00:05:55,500 That's it. 87 00:05:55,690 --> 00:05:56,610 That's the simple. 88 00:05:56,610 --> 00:06:01,940 If so, if you get the hang of this one, you now know what or if statements are right. 89 00:06:02,370 --> 00:06:12,010 And from here, let's go and talk about we have the ALS here, but we also have a term which is ayliffe. 90 00:06:12,660 --> 00:06:13,110 All right. 91 00:06:13,110 --> 00:06:16,160 We have ALS and we have Ayliffe. 92 00:06:16,590 --> 00:06:18,920 So what is the difference between them? 93 00:06:19,170 --> 00:06:20,760 What's the purpose of else? 94 00:06:21,180 --> 00:06:25,270 We know already, but what's the purpose of our if we don't know yet? 95 00:06:25,770 --> 00:06:30,440 So let's hear off again with the theory and see an example straight ahead. 96 00:06:30,750 --> 00:06:39,240 So as we saw in the syntax example above, that if statement returns a false value, we are only the 97 00:06:39,240 --> 00:06:41,970 code that is indented inside the else. 98 00:06:42,000 --> 00:06:43,650 Right, which was print. 99 00:06:43,860 --> 00:06:47,530 No, but on that's in there, we hope. 100 00:06:47,700 --> 00:06:49,530 And we have only one condition. 101 00:06:49,530 --> 00:06:53,190 We asked a single question and we have only two options. 102 00:06:53,430 --> 00:06:56,970 We can run either prints or print. 103 00:06:56,970 --> 00:06:59,180 No, we don't have any other options right here. 104 00:06:59,960 --> 00:07:00,410 All right. 105 00:07:00,840 --> 00:07:03,210 So we have only one condition. 106 00:07:06,830 --> 00:07:14,120 It's either true and then we print, then we execute this one or it's a false and then we execute this 107 00:07:14,120 --> 00:07:14,730 one, right. 108 00:07:15,320 --> 00:07:23,660 But what if we have lots of conditions to take into consideration and not only one, then we should 109 00:07:23,660 --> 00:07:25,550 use our if as well. 110 00:07:26,000 --> 00:07:29,240 And then we ship its duplicates are. 111 00:07:31,930 --> 00:07:45,130 All right, so Aliev is for all mede conditions while alse is for the last condition that he is used 112 00:07:45,130 --> 00:07:48,960 as in default exit point for the condition part. 113 00:07:49,420 --> 00:07:51,660 And let's see an example for this. 114 00:07:51,670 --> 00:07:52,030 All right. 115 00:07:52,330 --> 00:07:52,980 Right here. 116 00:07:52,990 --> 00:07:55,600 We also are going to have X equals three. 117 00:07:55,810 --> 00:07:57,490 Then we ask a question. 118 00:07:57,880 --> 00:07:59,650 Does X is bigger? 119 00:07:59,670 --> 00:08:01,650 Is is bigger than four. 120 00:08:02,260 --> 00:08:02,950 All right. 121 00:08:03,070 --> 00:08:05,400 So X is not bigger than four. 122 00:08:05,420 --> 00:08:06,990 So we have a false here. 123 00:08:07,180 --> 00:08:12,970 So this would not be executed because false is not executed, is never executed. 124 00:08:13,720 --> 00:08:19,420 Then we will like to ask another question, Ali, if X bigger than five. 125 00:08:19,450 --> 00:08:19,920 All right. 126 00:08:19,930 --> 00:08:23,500 So it's like a continuation of this if. 127 00:08:23,620 --> 00:08:24,130 All right. 128 00:08:24,370 --> 00:08:34,960 So if by the way, I wrote here in the sketch bolded in yellow elif stands for or else if I so have 129 00:08:35,230 --> 00:08:39,190 if x bigger than for false. 130 00:08:39,220 --> 00:08:42,580 So this one would not be executed then we ask. 131 00:08:43,520 --> 00:08:48,710 Alice, if it's bigger than five, we just go with the flow from top to bottom, right? 132 00:08:49,520 --> 00:08:58,070 So after that we ask else if it's bigger than five, also false, then we ask again, else if it's bigger 133 00:08:58,070 --> 00:08:58,820 than 15. 134 00:08:58,970 --> 00:09:01,010 Also, it falls here. 135 00:09:01,010 --> 00:09:01,970 Also a false. 136 00:09:03,270 --> 00:09:12,600 Right, and then all of these values, all these Output's values were false, boolean false, and then 137 00:09:12,600 --> 00:09:17,670 we got to the last one, which is alse, and then we just go straight ahead. 138 00:09:17,680 --> 00:09:26,010 You print five and the only code that would be executed right here among these these conditions right 139 00:09:26,010 --> 00:09:30,740 here, the only one that would be executed is print five right here. 140 00:09:30,930 --> 00:09:31,740 And why? 141 00:09:32,400 --> 00:09:39,900 The reason is the reason is for the last condition that is used as a default exit point, meaning if 142 00:09:39,900 --> 00:09:46,230 all of these are false, then our code would run what we have here in else. 143 00:09:46,800 --> 00:09:48,660 This is the default exit point. 144 00:09:48,780 --> 00:09:54,180 If all of these are output's are false, then else will be executed. 145 00:09:54,780 --> 00:09:55,220 All right. 146 00:09:55,230 --> 00:09:57,210 And right here, let's see the sketch. 147 00:10:00,320 --> 00:10:09,110 So this is the flow that we have just went over and what we basically see here is the start while we 148 00:10:09,110 --> 00:10:11,810 execute the class, that the cold is in it. 149 00:10:12,230 --> 00:10:14,570 And then we have the first if condition. 150 00:10:14,930 --> 00:10:20,000 If the F if condition is true, then run the cold ball inside. 151 00:10:20,000 --> 00:10:27,140 If this is this part is the same as the previous part, then if it's false, basically, if like we 152 00:10:27,140 --> 00:10:35,660 have a true so the cold exits the if condition it exits it and continues to the next block of cold, 153 00:10:35,810 --> 00:10:37,490 the if condition is completed. 154 00:10:37,680 --> 00:10:39,950 If we have a true value we just continue on. 155 00:10:39,980 --> 00:10:40,280 All right. 156 00:10:40,640 --> 00:10:44,420 But if it's a false then we start a different flow here. 157 00:10:44,540 --> 00:10:49,100 As you can see on the left, we first check is the first el. 158 00:10:49,110 --> 00:10:58,250 If true, if it's true, round the ball, cold inside the first hour, if then if it's a false all right 159 00:10:58,520 --> 00:11:00,650 then go to the second el if. 160 00:11:01,660 --> 00:11:08,140 A condition, and then if that one is true, then Rhonda called in the second ayliffe, if this one 161 00:11:08,140 --> 00:11:10,900 is false, then go straight ahead to the third one. 162 00:11:11,110 --> 00:11:16,550 And if the third one is false, then go inside the default exit point. 163 00:11:16,960 --> 00:11:26,170 Let me just quickly add here the missing parts, because we also need to mention here that what happens, 164 00:11:26,170 --> 00:11:34,750 whether we have a false value for these you else ifs all right like that. 165 00:11:35,020 --> 00:11:39,250 And also mention here that. 166 00:11:41,590 --> 00:11:46,420 What happens if we have a true value for the house? 167 00:11:46,450 --> 00:11:49,010 If so, let me just put it right here. 168 00:11:49,340 --> 00:11:49,750 Yeah. 169 00:11:51,410 --> 00:12:01,580 So I think it's a bit self explanatory because we basically have the same structure and a basic if and 170 00:12:01,580 --> 00:12:09,470 also in an L if the difference is that in our if we just have several examples of several conditions 171 00:12:10,430 --> 00:12:16,130 asked and whether in the flow we get a true for one of them. 172 00:12:16,140 --> 00:12:23,510 So the the code just stops dealing with the if statement just goes on further in the code. 173 00:12:23,720 --> 00:12:24,050 All right. 174 00:12:24,050 --> 00:12:26,180 So the flow goes again like this. 175 00:12:26,420 --> 00:12:29,630 We start the code which first check the main if condition. 176 00:12:29,870 --> 00:12:36,730 If the main condition is true, we just run the code under it and we exit the condition completely. 177 00:12:36,980 --> 00:12:40,040 All of these left part here does not run at all. 178 00:12:40,670 --> 00:12:45,770 Only of the main if condition is false, then we check each and every ELIF. 179 00:12:46,430 --> 00:12:54,020 And also if all of them are false, then as a default exit point, we run the aspart. 180 00:12:54,830 --> 00:12:55,280 All right. 181 00:12:55,280 --> 00:13:00,910 I think this summarize pretty nicely the basic part of conditions. 182 00:13:01,250 --> 00:13:07,760 And it's a very, very useful and very crucial for you to understand this topic, because I can say 183 00:13:07,760 --> 00:13:14,720 that a lot of the code that we are going to write further on is based on if conditions and also on loops 184 00:13:14,720 --> 00:13:17,240 that which we our following topic. 185 00:13:17,630 --> 00:13:20,090 So try to read this material again. 186 00:13:20,090 --> 00:13:27,860 By the way, these this document is attached to the current video and Udemy in UDD toolbar. 187 00:13:28,160 --> 00:13:32,780 And try just to watch that, just to read it again. 188 00:13:33,080 --> 00:13:39,760 I think it would be very useful and in the next video will try to see more examples in the code in each 189 00:13:39,770 --> 00:13:44,210 arm and see how can we understand this. 190 00:13:44,560 --> 00:13:45,710 These flows better. 191 00:13:45,950 --> 00:13:53,750 We will see both examples for simple if and for if examples in the code in the next video. 192 00:13:54,110 --> 00:13:54,520 All right. 193 00:13:54,680 --> 00:13:55,610 That's about it. 194 00:13:55,950 --> 00:14:03,170 And next, after or after the examples, we will have a quick practice and then we'll go straight ahead 195 00:14:03,380 --> 00:14:06,470 for the advanced part off if condition statements. 196 00:14:06,800 --> 00:14:07,100 All right. 197 00:14:07,250 --> 00:14:08,740 That's about it for this lecture. 198 00:14:08,750 --> 00:14:09,950 I'll see you in the next one. 199 00:14:10,100 --> 00:14:11,290 Thank you and bye bye.