1 00:00:13,010 --> 00:00:19,070 Hi and welcome to all of you, and today we'll continue discussing for loops and once we've covered 2 00:00:19,070 --> 00:00:24,920 the basic theory in the previous lectures, I think it's time to head off to the advanced topics. 3 00:00:25,250 --> 00:00:27,980 And also an important note. 4 00:00:28,190 --> 00:00:34,520 Don't worry if you find this lecture a bit challenging and a bit hard, because, first of all, we're 5 00:00:34,520 --> 00:00:37,760 an advanced stage stages and for loops. 6 00:00:37,910 --> 00:00:45,170 And also, I promise you that in the next video you will see these same examples, these same topics, 7 00:00:45,440 --> 00:00:48,170 live and patient life coding. 8 00:00:48,170 --> 00:00:53,810 And I will apply them in my term and also going to explain them thoroughly again. 9 00:00:53,990 --> 00:00:56,630 And I'm sure that you're going to get the hang of it once. 10 00:00:56,630 --> 00:00:59,150 I'll explaining once, twice or three times. 11 00:00:59,480 --> 00:01:01,340 It's nothing complicated. 12 00:01:01,550 --> 00:01:03,800 After you break it down into small pieces. 13 00:01:03,800 --> 00:01:04,940 Everything is easy. 14 00:01:05,420 --> 00:01:06,560 Trust me on this one. 15 00:01:07,370 --> 00:01:14,090 So you will see these exact examples in the next lecture as well with small modifications and you will 16 00:01:14,090 --> 00:01:16,970 see how can I apply in life coding on Pichon? 17 00:01:17,650 --> 00:01:18,020 All right. 18 00:01:18,290 --> 00:01:23,270 So let's find out what these the range function and how to use it with loops. 19 00:01:23,570 --> 00:01:30,140 So to run the loop for a specific, specific number of times, we can use the range function, which 20 00:01:30,140 --> 00:01:33,360 basically will pass the loop a sequence of numbers. 21 00:01:33,380 --> 00:01:33,690 All right. 22 00:01:33,710 --> 00:01:41,180 So the only thing that the range function does, it passes a single number on each iteration of the 23 00:01:41,180 --> 00:01:41,690 loop. 24 00:01:41,690 --> 00:01:43,910 It passes a number to the loop. 25 00:01:44,150 --> 00:01:44,660 That's it. 26 00:01:45,740 --> 00:01:46,940 So this is the basic rule. 27 00:01:47,450 --> 00:01:51,860 And we have like the basic functionality of range. 28 00:01:51,860 --> 00:01:57,460 And we have also some interesting features that are optional to use with the range. 29 00:01:57,470 --> 00:02:00,590 So let's go all let's go over all of them. 30 00:02:00,620 --> 00:02:00,900 All right. 31 00:02:01,430 --> 00:02:11,120 So by default range function will start with a value zero and increase by one on each iteration and 32 00:02:11,120 --> 00:02:14,130 we'll stop at the limit that we have set for it. 33 00:02:14,690 --> 00:02:15,160 All right. 34 00:02:15,560 --> 00:02:17,600 So let's see an example right here. 35 00:02:17,600 --> 00:02:23,430 Example, a start from zero and then increment by one on each iteration. 36 00:02:23,780 --> 00:02:30,260 So as we just mentioned, by default range, we'll start with the default number zero and we'll increment 37 00:02:30,260 --> 00:02:32,060 by one on each iteration. 38 00:02:33,050 --> 00:02:38,900 Notice in our example, six is not included. 39 00:02:38,930 --> 00:02:39,290 All right. 40 00:02:39,300 --> 00:02:43,540 So six is the maximum limit and is not included in the output. 41 00:02:43,820 --> 00:02:46,060 So you can see a for loop right here. 42 00:02:46,250 --> 00:02:52,700 And what basically happened that we don't have, like the structure that we have seen for in the previous 43 00:02:52,700 --> 00:03:02,870 lecture, four x, four X, I wanted to be with small letter for like cell in list like this. 44 00:03:02,870 --> 00:03:08,840 And here we have the list, for example, with one, two, three, four, five. 45 00:03:09,140 --> 00:03:10,420 It's not this case. 46 00:03:10,430 --> 00:03:10,700 All right. 47 00:03:10,700 --> 00:03:15,820 So the list is the whole, as we discussed, and one cell is each of these items. 48 00:03:16,370 --> 00:03:18,890 So now we're not having this thing. 49 00:03:19,160 --> 00:03:23,330 We're having four X in the range six. 50 00:03:23,720 --> 00:03:24,100 All right. 51 00:03:24,110 --> 00:03:29,300 So the loop will the loop will get numbers out of this function. 52 00:03:30,350 --> 00:03:33,600 And the first number would be zero from here. 53 00:03:33,620 --> 00:03:37,840 This is again, this is the hole, as we have seen right here. 54 00:03:38,420 --> 00:03:39,700 The least is the hole. 55 00:03:39,950 --> 00:03:47,240 So in our case, the range function is the hole and it will pass a number on each iteration in this 56 00:03:47,240 --> 00:03:50,630 case starting from zero to this X-ray here. 57 00:03:51,290 --> 00:03:51,770 All right. 58 00:03:51,800 --> 00:04:01,340 Again, this range function will pass a number on each iteration to this X right here, starting from 59 00:04:01,340 --> 00:04:07,730 zero for the first iteration, then one, and then the second iteration, then two in the third iteration, 60 00:04:07,730 --> 00:04:09,280 four and five. 61 00:04:09,290 --> 00:04:10,020 And that's it. 62 00:04:10,820 --> 00:04:11,360 All right. 63 00:04:11,540 --> 00:04:14,780 And then just to check how it works. 64 00:04:15,110 --> 00:04:15,530 All right. 65 00:04:15,530 --> 00:04:19,450 So what we have done right here, which is going to bring this X, right? 66 00:04:19,820 --> 00:04:23,500 So in the first iteration, we're going to get the zero here. 67 00:04:23,510 --> 00:04:23,780 All right. 68 00:04:23,790 --> 00:04:24,980 So we're going with the loop. 69 00:04:24,980 --> 00:04:28,190 We're getting zero and then we want to print print that X. 70 00:04:28,520 --> 00:04:28,820 All right. 71 00:04:28,820 --> 00:04:35,140 So this X in the first, first, first iteration, it is zero. 72 00:04:35,150 --> 00:04:36,380 So it's printed right here. 73 00:04:36,770 --> 00:04:45,530 Then in the second iteration, it's one third duration is two, three, four and five and six is not 74 00:04:45,530 --> 00:04:46,010 included. 75 00:04:46,010 --> 00:04:47,570 Six is the maximum limit. 76 00:04:47,960 --> 00:04:50,840 So it goes zero, one, two, three, four and five. 77 00:04:51,080 --> 00:04:57,240 And then it stops, then the fall, then the called X is the follow up and goes further in the code 78 00:04:57,240 --> 00:04:57,570 down. 79 00:04:58,040 --> 00:04:58,540 All right. 80 00:04:58,790 --> 00:04:59,630 It's not pretty. 81 00:04:59,630 --> 00:05:02,270 It's not it's pretty easy, actually, if you think of it right. 82 00:05:02,570 --> 00:05:08,460 Each time we get one number out of here, starting from zero going up plus one on each iteration. 83 00:05:08,510 --> 00:05:09,020 That's it. 84 00:05:09,500 --> 00:05:11,060 Basic and simple as that. 85 00:05:12,400 --> 00:05:20,380 From we're going to go one level up and we will see example be first of all, let's read here the second 86 00:05:20,380 --> 00:05:20,730 both. 87 00:05:20,740 --> 00:05:21,490 It's optional. 88 00:05:21,490 --> 00:05:31,120 As you can see, we can also give a start and end limits, too, for the range function. 89 00:05:31,390 --> 00:05:31,930 All right. 90 00:05:32,140 --> 00:05:36,990 And tell it on what number to start and on what number to end. 91 00:05:37,330 --> 00:05:43,190 So in the first example, it start by starts by default from zero and stops at six. 92 00:05:43,570 --> 00:05:44,170 All right. 93 00:05:44,530 --> 00:05:49,210 But now let's see how we can set it a start and end numbers. 94 00:05:49,240 --> 00:05:49,750 All right. 95 00:05:51,070 --> 00:06:02,200 Also, like an example, a in this case, the number the number will increment by plus one on each iteration. 96 00:06:02,620 --> 00:06:04,420 OK, so it looks like this. 97 00:06:04,720 --> 00:06:12,610 You see right now we're having two numbers inside the brackets and these two numbers are stating the 98 00:06:12,610 --> 00:06:15,890 starting point and the end point of the loop. 99 00:06:16,150 --> 00:06:22,060 So in the first iteration, this is going to get the number three and also we're going to print it out. 100 00:06:22,060 --> 00:06:28,900 Obviously, the second iteration, it will before it will be printed, then five and then six. 101 00:06:29,590 --> 00:06:35,550 Also, like in the previous example, the maximum limit is not included. 102 00:06:35,560 --> 00:06:37,510 So the maximum limit here is seven. 103 00:06:37,720 --> 00:06:42,070 And as you can see in the output, we would not see the seventh number. 104 00:06:42,260 --> 00:06:43,340 It's not included. 105 00:06:43,570 --> 00:06:43,960 All right. 106 00:06:43,970 --> 00:06:45,470 So this is a starting point. 107 00:06:45,820 --> 00:06:47,050 This is the end point. 108 00:06:47,290 --> 00:06:51,130 And each iteration will be increased by plus one. 109 00:06:51,940 --> 00:06:52,470 All right. 110 00:06:52,930 --> 00:06:54,050 This is an example. 111 00:06:55,450 --> 00:06:57,980 Now, let's go to bullet number three. 112 00:06:58,360 --> 00:07:06,970 Additionally, we can also pass the rate, the range method, the incremental margin number for each 113 00:07:06,970 --> 00:07:08,050 iteration. 114 00:07:08,080 --> 00:07:16,210 OK, so in these two examples, we have seen incrimination by plus one on each iteration or each cycle. 115 00:07:16,360 --> 00:07:20,030 Each cycle of the loop was increasing by plus one. 116 00:07:20,350 --> 00:07:23,620 Here we have zero, then one, two and so on. 117 00:07:23,770 --> 00:07:27,490 And here we started at three, then four, five and six. 118 00:07:27,490 --> 00:07:30,220 Each iteration goal goes was plus one. 119 00:07:30,910 --> 00:07:33,010 But here and this example. 120 00:07:33,040 --> 00:07:33,520 All right. 121 00:07:33,760 --> 00:07:39,290 We can give the third number inside the brackets right here. 122 00:07:39,790 --> 00:07:40,330 All right. 123 00:07:40,690 --> 00:07:43,600 So here we have the starting point. 124 00:07:44,200 --> 00:07:46,530 Here we have the end point. 125 00:07:46,840 --> 00:07:48,670 Same as we had an example. 126 00:07:48,670 --> 00:07:50,590 B is right here. 127 00:07:50,620 --> 00:07:59,620 We have the incremental number, meaning it's each iteration, each cycle would be increased by three. 128 00:07:59,840 --> 00:08:03,840 OK, so then we're going to start a three right here. 129 00:08:03,840 --> 00:08:04,750 We're going to print it. 130 00:08:05,770 --> 00:08:11,180 Sorry, it's it's not the correct numbers, so we're going to start let's make it a bit smaller, so 131 00:08:11,180 --> 00:08:13,180 will we be a bit easier like 12 or. 132 00:08:13,180 --> 00:08:13,350 Right. 133 00:08:13,690 --> 00:08:19,030 So we'll start with three, then we have six, then we have nine. 134 00:08:19,570 --> 00:08:22,090 And then we have 12 while 12. 135 00:08:23,330 --> 00:08:30,080 As before, not included, so I'm going to erase all of these numbers right here, because always the 136 00:08:30,080 --> 00:08:32,540 last the maximum range is not included. 137 00:08:32,570 --> 00:08:35,140 So, again, let's explain it again. 138 00:08:35,690 --> 00:08:38,110 We're starting this is the starting limit. 139 00:08:38,390 --> 00:08:40,100 This is the end limit. 140 00:08:40,340 --> 00:08:48,400 And this is the incremental number like plus what number we're going to give on each cycle. 141 00:08:49,160 --> 00:08:54,210 So we're starting with three, meaning this is this is what we get right here in the print. 142 00:08:54,470 --> 00:08:58,580 So in the first cycle, the print will be printing three. 143 00:08:59,120 --> 00:09:01,820 In the second cycle, we're going to get the last three. 144 00:09:01,820 --> 00:09:02,210 Right. 145 00:09:02,420 --> 00:09:04,640 So you're going to get six here. 146 00:09:06,270 --> 00:09:13,860 And then in the third cycle, we're going to have nine, all right, and then we're going to have the 147 00:09:13,860 --> 00:09:16,470 fourth one because our limit is 12. 148 00:09:16,890 --> 00:09:21,900 But like always, the maximum limit here is not included. 149 00:09:21,930 --> 00:09:25,410 So this would not be inside the print. 150 00:09:25,580 --> 00:09:29,310 OK, this is as always, so the maximum is not included. 151 00:09:29,520 --> 00:09:33,460 Samia's here you see that seven does not appear in the output. 152 00:09:33,510 --> 00:09:34,290 This is the rule. 153 00:09:34,470 --> 00:09:34,970 All right. 154 00:09:35,310 --> 00:09:37,480 So it's not very complicated. 155 00:09:37,500 --> 00:09:39,080 You have three examples here. 156 00:09:39,360 --> 00:09:45,690 Feel free also to use the PDF attachment file to read over the material. 157 00:09:45,690 --> 00:09:49,660 And I will see you in the next video where you see these examples live in Pichon. 158 00:09:49,680 --> 00:09:50,190 Thank you.