1 00:00:00,510 --> 00:00:02,960 Hello and welcome to this video. 2 00:00:03,000 --> 00:00:10,950 In this video I'm going to introduce you to another conditional type of statement called the TELL IF 3 00:00:11,220 --> 00:00:20,580 statement the L if statement is calm like a bridge or a combination of one else statement and an if 4 00:00:20,970 --> 00:00:29,850 statement was kind of like to type of statements combined to one the L if statements are basically used 5 00:00:29,850 --> 00:00:39,840 to check for multiple expressions that are true in your program so they check for several conditions 6 00:00:39,840 --> 00:00:48,990 that are true and if one of them is true it execute the first one it finds and then ignores the rest. 7 00:00:48,990 --> 00:00:55,470 So when you have an if statement if statement would check if a condition is true and then execute the 8 00:00:55,470 --> 00:01:02,890 block of code inside that if block and if the condition is not true it doesn't do anything. 9 00:01:03,120 --> 00:01:10,110 A eal or L if statement is kind of like multiple if statements. 10 00:01:10,260 --> 00:01:16,800 So it gives you options to check for conditions that are true. 11 00:01:17,160 --> 00:01:25,530 They will only execute a block of code as soon as one of the conditions evaluates to true. 12 00:01:25,530 --> 00:01:30,350 It will only execute that block and it will ignore the other code. 13 00:01:31,200 --> 00:01:37,350 So this is what a typical syntax looks like for an L if statement. 14 00:01:37,370 --> 00:01:44,790 So you start with the if statement which will count as the first condition to check if is true and if 15 00:01:44,790 --> 00:01:50,140 it's true you execute the block of code that is indented for that. 16 00:01:50,190 --> 00:01:57,500 If block if that condition is not met it goes onto the l. 17 00:01:57,510 --> 00:02:01,530 If block and checks for the second condition that is true. 18 00:02:01,530 --> 00:02:10,230 If that condition is true it will execute the block of code on the L if condition is very important 19 00:02:10,230 --> 00:02:15,990 to take note of the colon colon tells Python to execute a block of code. 20 00:02:15,990 --> 00:02:22,770 It also tells Python that you are starting a new line of code and the code must be indented indentation 21 00:02:22,770 --> 00:02:28,850 is important so that you know what could block belongs to setting condition. 22 00:02:28,950 --> 00:02:34,930 So let me show you an example of how the L if statement can work. 23 00:02:35,280 --> 00:02:37,100 So I've already got a python file. 24 00:02:37,110 --> 00:02:45,850 I'm just going to create two variables I create variable a and I'll give it a value of seven. 25 00:02:45,870 --> 00:02:53,020 Now create another variable B and I'll give it a value of 8. 26 00:02:53,030 --> 00:03:06,920 Now I can start with my if block so say if the value a is greater than the value B then I'll do my colon 27 00:03:07,610 --> 00:03:12,370 to tell Python that I want to start a new line of code. 28 00:03:12,460 --> 00:03:19,070 Presenter You can see automatically indents it for me so I'm gonna type in a print statement. 29 00:03:19,070 --> 00:03:26,180 I will say print and inside the parentheses of that print function. 30 00:03:26,190 --> 00:03:29,850 I'm going to specify the code that will execute. 31 00:03:30,050 --> 00:03:37,400 So I'm going to say ay ay I'm referring to the value of the variable a no say you can type in anything 32 00:03:37,400 --> 00:03:37,850 you want. 33 00:03:37,850 --> 00:03:41,020 Doesn't really matter is smaller. 34 00:03:41,860 --> 00:03:50,450 And then our exit the string with a comma it's important you add your comma so that the interpreter 35 00:03:50,450 --> 00:03:55,720 knows the difference between a normal variable and a normal string. 36 00:03:55,720 --> 00:03:56,180 All right. 37 00:03:56,180 --> 00:04:04,940 So now this is my if block so you can see by indentation you can tell that this block of code belongs 38 00:04:04,940 --> 00:04:06,690 to this if block. 39 00:04:06,800 --> 00:04:11,180 So now I want to add an else block. 40 00:04:11,390 --> 00:04:17,230 You can add as many L if block if you want. 41 00:04:17,250 --> 00:04:19,700 So you don't necessarily have to have just one. 42 00:04:19,700 --> 00:04:28,280 If you want to have several conditions to test for true you can add as many as you want something else. 43 00:04:28,280 --> 00:04:35,080 If I'm checking on other condition e.g. variable b let me reverse that. 44 00:04:35,080 --> 00:04:47,530 I'll say if the variable B which is eight years is greater than the variable a two column then I want 45 00:04:47,650 --> 00:04:50,730 certain block of code to execute. 46 00:04:51,040 --> 00:05:00,550 So inside onto a print statement and inside that print statement I will specify what I want done. 47 00:05:00,630 --> 00:05:05,570 Let's keep the string and do a comma and say a. 48 00:05:05,670 --> 00:05:15,070 So this is my else if block you can have as many as you want depending on how many conditions you want 49 00:05:15,070 --> 00:05:17,260 to test for that are true. 50 00:05:17,430 --> 00:05:27,880 The code will check the Port St. side beef block first that is a block that will run first is checking 51 00:05:28,080 --> 00:05:30,370 is the value of a which is seven. 52 00:05:30,370 --> 00:05:33,640 Is it greater than B. 53 00:05:33,820 --> 00:05:35,020 It is not. 54 00:05:35,020 --> 00:05:36,460 So that's condition. 55 00:05:36,460 --> 00:05:38,870 This condition is false. 56 00:05:38,880 --> 00:05:41,620 That means this code here will not run. 57 00:05:41,620 --> 00:05:47,810 So it jumps to this other condition the L if block and checks the condition. 58 00:05:47,860 --> 00:05:51,890 Notice I'm using the operators to check. 59 00:05:51,910 --> 00:05:53,260 This is the greater than sign. 60 00:05:53,290 --> 00:05:54,450 This is a greater than. 61 00:05:54,460 --> 00:06:01,660 There are many other operators comparison operators and logical operators you can use a value. 62 00:06:01,660 --> 00:06:05,250 Just use the greater down just for simplicity. 63 00:06:05,350 --> 00:06:10,870 Depending on what condition you are testing you use the appropriate operator. 64 00:06:10,930 --> 00:06:14,000 So this block in the IFF is wrong. 65 00:06:14,020 --> 00:06:16,320 That is it has not tested true. 66 00:06:16,330 --> 00:06:26,020 So that code will not run the code in the L. if is true because B is greater than a B's 8 which is greater 67 00:06:26,020 --> 00:06:27,030 than 7. 68 00:06:27,040 --> 00:06:33,960 So what will happen this block of code will execute c if I press play. 69 00:06:34,200 --> 00:06:42,110 You can see here this code here what I say B is bigger than a B is 8. 70 00:06:42,110 --> 00:06:49,980 It says 8 is bigger than 7 so you can see that block of code executes both the first one does not execute 71 00:06:50,380 --> 00:06:53,420 so you can see the importance of the L. 72 00:06:53,440 --> 00:07:00,300 If so you can add as many L if in your code as required. 73 00:07:00,310 --> 00:07:09,360 I've only just used 2 1 just for simplicity so that's it for this video on the L if conditional statement. 74 00:07:09,370 --> 00:07:10,630 Thank you for watching. 75 00:07:10,630 --> 00:07:11,720 Bye for now.