1 00:00:00,270 --> 00:00:00,920 Hello everybody. 2 00:00:01,020 --> 00:00:02,510 And welcome back. 3 00:00:03,970 --> 00:00:05,110 In the previous video. 4 00:00:05,110 --> 00:00:09,310 We saw how we can use the if l statement in our program. 5 00:00:09,430 --> 00:00:13,840 Now let's see another statement that we can use which was the false statement. 6 00:00:13,840 --> 00:00:17,410 So it basically says as it basically does as it says. 7 00:00:17,410 --> 00:00:19,290 So for something do something. 8 00:00:19,910 --> 00:00:27,170 Now the basic use of this would be so let me open up my Python interpreter. 9 00:00:27,160 --> 00:00:35,070 The basic use would be or what we will use most likely is for something in range of a few numbers. 10 00:00:35,070 --> 00:00:37,600 So let me just show you what I mean. 11 00:00:37,600 --> 00:00:43,810 So let's say no equals 1 and then we want to do this command right here. 12 00:00:43,810 --> 00:00:50,740 So for AI or basically for anything for AI in the range of range is basically an inbuilt function. 13 00:00:50,740 --> 00:00:56,910 So in range 1 comma 10 then we close the parentheses then two dots. 14 00:00:56,950 --> 00:01:00,110 So let's first explain what this means. 15 00:01:00,160 --> 00:01:05,560 The range is basically it is saying for some AI variable in the range from 1 to 10. 16 00:01:05,560 --> 00:01:16,030 So this I will take the values from 1 to 10 do and then your presenter then tab it so we can push it 17 00:01:16,030 --> 00:01:18,390 forward and just type here. 18 00:01:18,570 --> 00:01:30,230 No equals no plus I so let's press here enter enter once again and if I just could not type number once 19 00:01:30,230 --> 00:01:33,810 again you would see that our number is now forty six. 20 00:01:33,810 --> 00:01:39,860 Now if you did not understand this you are probably all you're probably ask yourself how is the number 21 00:01:39,860 --> 00:01:41,570 right now 46. 22 00:01:41,630 --> 00:01:46,600 So let's take our in-depth view on this right here. 23 00:01:46,640 --> 00:01:51,500 So we first specify our number to be 1 then we specify this right here. 24 00:01:51,500 --> 00:01:57,830 So for i in range 1 2 through 10 do number equals nine plus 1. 25 00:01:57,830 --> 00:02:04,570 So for the first for the first circle of this command I will be equal 1. 26 00:02:04,670 --> 00:02:06,040 So it will then do. 27 00:02:06,110 --> 00:02:09,370 Number which is 1 equals number plus I. 28 00:02:09,530 --> 00:02:13,510 Which is then 2 so number is 1 and I is 1 in the first circle. 29 00:02:13,820 --> 00:02:16,590 And then our number will become 2. 30 00:02:16,760 --> 00:02:19,270 Then it will go back and then it will do that. 31 00:02:19,280 --> 00:02:21,120 The AI is now 2. 32 00:02:21,140 --> 00:02:24,200 So since we already did 1 and now it will be two. 33 00:02:24,200 --> 00:02:28,590 So now this will be two equals two plus two. 34 00:02:28,910 --> 00:02:32,770 Since our IDE is now two or one plus two. 35 00:02:32,780 --> 00:02:33,560 Pardon me. 36 00:02:33,830 --> 00:02:42,210 And then it will do it all the way through 10 and then it will give us the output of all the added numbers 37 00:02:42,210 --> 00:02:44,190 together of which is forty six. 38 00:02:44,280 --> 00:02:47,430 So that is how the for loop works. 39 00:02:47,460 --> 00:02:54,500 Now let's see how we can also use it in order to for example increase all the numbers in the list. 40 00:02:54,510 --> 00:03:01,220 Now we didn't really cover the list yet but just type what I do so let's make our third program. 41 00:03:01,320 --> 00:03:08,620 Now I know Python 3 but by we specify the path I will not say why anymore since I did it already twice. 42 00:03:08,830 --> 00:03:13,760 And right now I have to specify the path we want to print to make a list. 43 00:03:13,800 --> 00:03:18,270 Now our list is basically a list of different strings or different numbers. 44 00:03:18,420 --> 00:03:23,050 In our case we will use a list of strings so no underscore based. 45 00:03:23,230 --> 00:03:24,500 We'll call it like that. 46 00:03:24,510 --> 00:03:30,590 You can call it anything you want and we specify lists with these brackets. 47 00:03:30,600 --> 00:03:36,660 We do not the normal brackets but with these brackets right here and then we specify the numbers in 48 00:03:36,660 --> 00:03:40,530 our list which would be 1 2 3 4 5. 49 00:03:40,680 --> 00:03:42,670 And then we close the brackets. 50 00:03:42,780 --> 00:03:44,670 So this is how you specify a list. 51 00:03:44,670 --> 00:03:49,150 You can put any numbers here you want divided by the comma. 52 00:03:49,290 --> 00:03:55,860 And right now what we want to do is use our for loop in order to for example increase each number from 53 00:03:55,860 --> 00:03:56,910 list by 1. 54 00:03:56,910 --> 00:03:59,290 Now how do we do that. 55 00:03:59,300 --> 00:04:00,470 Well it's a little bit different. 56 00:04:00,470 --> 00:04:02,960 So do most of the commands is actually the same. 57 00:04:02,960 --> 00:04:10,670 So what we want to do is for i in range and we want to open up our brackets but not type here the range 58 00:04:10,670 --> 00:04:16,730 we want to type your length since we want the length of this list right here to be the range of our 59 00:04:16,790 --> 00:04:17,660 loop. 60 00:04:17,660 --> 00:04:25,310 So for I enrage and then open brackets Len with 10 which stands for Len and then the length of our number 61 00:04:25,310 --> 00:04:27,540 list. 62 00:04:27,720 --> 00:04:35,990 No list then we need to call those two brackets and then put these two dots right here so this basically 63 00:04:35,990 --> 00:04:44,360 says for any number or not for any number for some variable i in range of the length of number lists 64 00:04:45,140 --> 00:04:48,110 we want to perform the number list 65 00:04:51,020 --> 00:04:54,970 of I plus equals 1. 66 00:04:55,010 --> 00:04:58,830 Now I will explain what this does in our future lectures for non. 67 00:04:58,970 --> 00:05:05,020 Just trust me that this will actually increase the numbers in our number list by 1. 68 00:05:05,420 --> 00:05:07,790 And if we printed the N number list 69 00:05:10,700 --> 00:05:11,680 and save this. 70 00:05:11,750 --> 00:05:20,030 So control X to exit c h mode plus X in order to make it executable and then we run the Python 3 you 71 00:05:20,030 --> 00:05:24,600 will see that I did the number list is no longer one two three four five. 72 00:05:24,710 --> 00:05:27,460 It is now two three four five six. 73 00:05:27,590 --> 00:05:31,680 So basically that is the simple use of the for loop. 74 00:05:31,700 --> 00:05:35,150 Now don't be worried about these lists right now. 75 00:05:35,210 --> 00:05:37,700 We will cover lists later on for now. 76 00:05:37,760 --> 00:05:40,490 I just want to show you what this can be used for. 77 00:05:40,490 --> 00:05:49,340 So for example if you had a list that is too large you could with this simple two line code change the 78 00:05:49,340 --> 00:05:54,910 values of all of those numbers in the list or in basically in our case increase them by 1. 79 00:05:54,920 --> 00:06:01,560 So for loops and if loops are very useful you will also see in the next videos Why yes. 80 00:06:01,850 --> 00:06:04,480 I basically only show you some of the most basic examples. 81 00:06:04,490 --> 00:06:11,000 They can be even more useful than this but for now on this would be enough in the next video which will 82 00:06:11,000 --> 00:06:14,980 cover a while loop that we will also use in our backdoor program. 83 00:06:14,990 --> 00:06:21,800 Well actually that is the most important book since we can specify some pretty pretty good things with 84 00:06:21,800 --> 00:06:22,240 it. 85 00:06:22,250 --> 00:06:28,730 I will show that in the next video and I hope you enjoy this one and I hope I see you in the next video. 86 00:06:28,730 --> 00:06:29,900 So take care.