1 00:00:11,850 --> 00:00:17,520 Hi, everyone, and welcome to this lecture, and as I promised in a previous video, I will now go 2 00:00:17,520 --> 00:00:24,620 over the examples of for loops the advanced sport so you could get the hang of it much easier. 3 00:00:24,900 --> 00:00:33,840 So once you open your project, just create a new file and you can call it for loops, advanced examples. 4 00:00:34,440 --> 00:00:39,240 And first of all, what I'm going to do is just leave a note here for loops advanced. 5 00:00:42,480 --> 00:00:49,920 Examples and the simple thing I'm going to do is going to copy the examples already had from our PDF 6 00:00:50,310 --> 00:00:53,340 to here, and let's go over them quickly. 7 00:00:53,490 --> 00:00:53,900 All right. 8 00:00:54,390 --> 00:00:56,580 So this is the first one between them. 9 00:00:56,580 --> 00:01:05,340 I'm going to leave print quotation marks and you can see it's marked with orange, and that's because 10 00:01:05,340 --> 00:01:06,840 it's a saved character. 11 00:01:07,410 --> 00:01:15,000 If you recall from previous lectures, what it does actually what it does, it just leaves us a empty 12 00:01:15,000 --> 00:01:18,500 line so we won't get mixed with the examples. 13 00:01:18,510 --> 00:01:18,860 All right. 14 00:01:19,290 --> 00:01:24,300 So what we had in the previous video, we had these three examples. 15 00:01:24,370 --> 00:01:24,870 All right. 16 00:01:25,860 --> 00:01:28,020 And let's run it. 17 00:01:29,390 --> 00:01:37,050 OK, so the first example right here, we're getting numbers out of the range function and starting 18 00:01:37,050 --> 00:01:40,260 from zero and increasing by one on each iteration. 19 00:01:40,380 --> 00:01:42,330 So first iteration gets zero. 20 00:01:42,630 --> 00:01:44,600 You see printout zero right here. 21 00:01:44,850 --> 00:01:47,460 Then in the second iteration, it's plus one. 22 00:01:47,470 --> 00:01:48,330 So it's one. 23 00:01:48,720 --> 00:01:52,440 So printing number one right here and so on and so on. 24 00:01:53,040 --> 00:01:58,550 Until we get to the limit, the limit is six and the maximum limit is excluded. 25 00:01:58,560 --> 00:02:02,010 So you can see number six is not in the printout right here. 26 00:02:02,490 --> 00:02:10,590 And in the second example, we're seeing minimum maximum limits, same logics starting from three now 27 00:02:10,800 --> 00:02:15,920 and printing it then going plus one each time until we get to the limit. 28 00:02:16,710 --> 00:02:23,190 And in the third example, these are the minimum and maximum limits and we're increasing by three on 29 00:02:23,190 --> 00:02:24,140 each iteration. 30 00:02:24,360 --> 00:02:33,240 So we can see here three then plus three in the second iteration, it's six and then we have nine and 31 00:02:33,240 --> 00:02:33,930 12. 32 00:02:34,200 --> 00:02:39,630 The last number is excluded because as we discussed, the maximum limit is excluded. 33 00:02:40,500 --> 00:02:40,900 All right. 34 00:02:41,040 --> 00:02:46,960 So from here, you can ask yourselves, why the hell do we need this range, range, method? 35 00:02:47,010 --> 00:02:47,310 All right. 36 00:02:47,310 --> 00:02:48,890 So we want to sound smart. 37 00:02:48,900 --> 00:02:53,220 We don't know new things, talk about it in interviews and stuff. 38 00:02:53,550 --> 00:02:55,230 But what is it good for? 39 00:02:55,230 --> 00:02:57,860 Actually, let's talk like real life. 40 00:02:57,870 --> 00:02:58,760 Why do we need it? 41 00:02:59,190 --> 00:03:01,420 Because it just gives us some number. 42 00:03:01,680 --> 00:03:03,250 So what can we do? 43 00:03:03,300 --> 00:03:06,930 It is we can maybe, like, multiply by ten, for example. 44 00:03:07,440 --> 00:03:08,240 Let's run. 45 00:03:09,450 --> 00:03:09,930 All right. 46 00:03:09,930 --> 00:03:12,030 So you get multiplied by ten. 47 00:03:12,270 --> 00:03:14,760 But what can we gain from it, actually? 48 00:03:14,790 --> 00:03:15,260 All right. 49 00:03:15,270 --> 00:03:16,680 What can we gain from this? 50 00:03:17,100 --> 00:03:23,730 So I'm just going to show you a quick example is going to erase all of this and leave the last example, 51 00:03:23,910 --> 00:03:26,670 which is the third from the previous video. 52 00:03:26,670 --> 00:03:29,850 I'm just going to maneuver it a little bit. 53 00:03:29,910 --> 00:03:30,410 All right. 54 00:03:30,870 --> 00:03:36,330 So I'm going to show you that you can do lots of interesting things with this range method. 55 00:03:37,170 --> 00:03:45,420 OK, so first of all, we have seen in the basic lectures regarding loops, we have seen, for example, 56 00:03:45,420 --> 00:03:46,500 that we had fruits. 57 00:03:46,980 --> 00:03:47,430 All right. 58 00:03:47,700 --> 00:03:49,080 And we had banana. 59 00:03:51,330 --> 00:03:58,550 Jerry, don't recall if it was in this order, but it doesn't example, it doesn't matter. 60 00:03:59,010 --> 00:04:06,720 And then what we did here, we just copy and then placed it right here and then we ran each cell each 61 00:04:06,720 --> 00:04:11,400 time and then we could, like, manipulate this and whatever we want. 62 00:04:11,580 --> 00:04:17,610 But we ran over these cells one by one, and it had some meaning or because we can control it. 63 00:04:17,880 --> 00:04:21,450 But in this example, we're just having some numbers. 64 00:04:21,500 --> 00:04:23,870 You what can we actually do with them? 65 00:04:24,150 --> 00:04:24,600 All right. 66 00:04:25,320 --> 00:04:29,640 So instead of having fruit here, I'm going to show you an interesting example. 67 00:04:29,650 --> 00:04:29,910 Right. 68 00:04:30,150 --> 00:04:35,640 So imagine yourself that you work in a company, you work in accounting, and your boss doesn't have 69 00:04:35,640 --> 00:04:40,850 a clue in coding and he gives you some guidelines for bonuses. 70 00:04:41,550 --> 00:04:42,090 All right. 71 00:04:43,500 --> 00:04:46,010 Like this gives you some guidelines. 72 00:04:46,020 --> 00:04:46,410 All right. 73 00:04:46,770 --> 00:04:49,950 And in these guidelines, he give you several rules. 74 00:04:49,950 --> 00:04:50,240 All right. 75 00:04:50,490 --> 00:05:01,380 He says to you, I want you to build a formula for Yula for bonus bonuses. 76 00:05:01,410 --> 00:05:01,800 All right. 77 00:05:03,120 --> 00:05:15,870 Employees are placed in cells by their work ethic, meaning some of them work hard, some of them do 78 00:05:15,870 --> 00:05:16,740 not work hard. 79 00:05:16,740 --> 00:05:24,510 And he doesn't want to tell us actually specifically the names and he just place them in certain places 80 00:05:24,510 --> 00:05:27,500 inside the list according to their work ethic. 81 00:05:27,520 --> 00:05:27,830 All right. 82 00:05:28,710 --> 00:05:34,860 He tells us that we give each employee. 83 00:05:39,060 --> 00:05:48,990 Implore e a bonus, which will be based on his place in the list. 84 00:05:50,650 --> 00:05:54,490 Multiplied by 100. 85 00:05:56,680 --> 00:06:06,310 All right, multiplied by 100, meaning multiply this number by one hundred, and this would be his 86 00:06:06,310 --> 00:06:06,880 bonus. 87 00:06:07,150 --> 00:06:07,570 All right. 88 00:06:07,570 --> 00:06:11,440 So place multiplied by a hundred. 89 00:06:14,840 --> 00:06:15,770 This is the bonus. 90 00:06:17,270 --> 00:06:17,640 All right. 91 00:06:18,830 --> 00:06:20,720 And the boss said. 92 00:06:24,840 --> 00:06:25,950 To give bonus. 93 00:06:28,540 --> 00:06:34,780 By jumping plus three each time in the list. 94 00:06:36,190 --> 00:06:44,170 All right, so just going to make a quick list of salaries here, and it's going to be one thousand 95 00:06:45,280 --> 00:06:55,820 to three for all four thousand, five, six, seven, eight and nine. 96 00:06:55,990 --> 00:06:56,360 All right. 97 00:06:56,440 --> 00:06:57,430 These are the salaries. 98 00:06:57,730 --> 00:06:59,580 Some of these employees work hard. 99 00:06:59,740 --> 00:07:01,690 Some of these did not work hard. 100 00:07:01,810 --> 00:07:04,540 And the boss wants to give them bonuses. 101 00:07:04,540 --> 00:07:06,760 He does not want to tell accounting. 102 00:07:07,390 --> 00:07:08,980 What are their names or something. 103 00:07:09,010 --> 00:07:09,170 Right. 104 00:07:09,250 --> 00:07:11,540 Just a discrete bonus plan. 105 00:07:11,650 --> 00:07:11,850 Right. 106 00:07:12,820 --> 00:07:16,210 And now he wants us to do the following thing here. 107 00:07:16,210 --> 00:07:24,520 I'm going to place the numbers zero to nine because we have sales zero one, two, three, four, five, 108 00:07:24,550 --> 00:07:26,830 six, seven and eight. 109 00:07:27,130 --> 00:07:33,490 And right here we had the same number because remember that the number nine is not included once we 110 00:07:33,490 --> 00:07:34,180 run the loop. 111 00:07:34,510 --> 00:07:38,500 So basically we have eight, eight iterations here. 112 00:07:38,500 --> 00:07:38,880 All right. 113 00:07:39,070 --> 00:07:43,150 And also we have applied bosses rules to jump by three each time. 114 00:07:44,020 --> 00:07:55,000 This one we'll call it place or right place because we call it place right here, Blayse and in here, 115 00:07:55,000 --> 00:07:59,800 which is going to go for we're going to go for the formula. 116 00:08:00,130 --> 00:08:01,720 So we have here salary. 117 00:08:04,170 --> 00:08:13,670 With bonus like this, and we're going to do the following thing, we're going to extract extra values 118 00:08:13,680 --> 00:08:20,040 out of the list by their places, so we're going to put the place because police is basically just a 119 00:08:20,040 --> 00:08:20,560 no. 120 00:08:21,030 --> 00:08:21,450 All right. 121 00:08:21,630 --> 00:08:23,450 Place is basically just a no. 122 00:08:23,460 --> 00:08:25,740 It's just a no out of this range method. 123 00:08:26,160 --> 00:08:27,720 So it start with zero. 124 00:08:28,560 --> 00:08:33,280 So if you put the number zero here instead of zero, what does it stand for? 125 00:08:33,300 --> 00:08:34,740 It stands for this value right here. 126 00:08:34,740 --> 00:08:35,020 Right. 127 00:08:36,510 --> 00:08:43,050 But now I'm going to use the workplace instead of zero because I want it to change in each iteration, 128 00:08:43,050 --> 00:08:49,310 because if I leave it zero here, so in the first time, it will be this this guy in the second time, 129 00:08:49,320 --> 00:08:51,930 it will also be this one and so on and so on. 130 00:08:51,930 --> 00:08:53,580 It will always be the first cell. 131 00:08:53,580 --> 00:08:56,970 But I don't want it to be always the first cell I want wanted to change. 132 00:08:56,970 --> 00:09:01,200 So I'm putting the place here so it would get numbers. 133 00:09:01,920 --> 00:09:05,580 The place will get numbers out of the range method. 134 00:09:05,580 --> 00:09:05,910 Right. 135 00:09:07,650 --> 00:09:11,190 And this thing I want to this is like the basic salary. 136 00:09:11,190 --> 00:09:11,450 Right? 137 00:09:11,460 --> 00:09:13,730 These numbers are the basic salary base salary. 138 00:09:14,110 --> 00:09:19,040 Want to added are place multiplied by hundreds. 139 00:09:19,050 --> 00:09:19,350 Right. 140 00:09:20,430 --> 00:09:21,720 This is what the boss said. 141 00:09:21,750 --> 00:09:22,020 Right. 142 00:09:23,080 --> 00:09:25,800 And then I just want to print it out. 143 00:09:29,050 --> 00:09:40,120 All right, so print are salary with bonus, I think we got it right, let's run it. 144 00:09:41,940 --> 00:09:42,420 Great. 145 00:09:42,900 --> 00:09:53,850 All right, so we started off with this one, and for some reason we're seeing here a small problem, 146 00:09:53,850 --> 00:09:57,720 right, because these two numbers seems to add up, right? 147 00:09:58,140 --> 00:10:01,170 Because we can see here, we're starting from here, right. 148 00:10:01,200 --> 00:10:02,400 Then we're jumping three. 149 00:10:02,400 --> 00:10:07,260 So this is one to three getting here and here. 150 00:10:07,260 --> 00:10:09,240 The number is three. 151 00:10:09,420 --> 00:10:09,860 All right. 152 00:10:11,070 --> 00:10:13,170 So we're getting four thousand. 153 00:10:14,160 --> 00:10:19,720 Four thousand three equals one thousand. 154 00:10:19,900 --> 00:10:24,520 So this is three thousand plus four thousand. 155 00:10:25,380 --> 00:10:27,130 So we're getting seven thousand. 156 00:10:27,180 --> 00:10:28,110 This is great. 157 00:10:28,470 --> 00:10:32,700 All right, then from here, we're jumping three, one, two, three. 158 00:10:32,700 --> 00:10:37,310 Getting here and here the number is six. 159 00:10:37,680 --> 00:10:44,140 So we have six thousand plus the base salary, which is seven thousand, which is this one. 160 00:10:44,640 --> 00:10:50,100 So six thousand plus seven thousand sums up for thirteen thousand. 161 00:10:50,790 --> 00:10:56,610 But here and the first cell right here we're getting 1000. 162 00:10:57,120 --> 00:10:58,410 Seems nothing happened here. 163 00:10:58,410 --> 00:10:58,680 Right. 164 00:10:59,280 --> 00:11:03,390 But remember that this Scelzi index is zero. 165 00:11:03,870 --> 00:11:04,430 All right. 166 00:11:04,530 --> 00:11:13,730 So this thing this thing comes with zero because zero multiplied by one thousand is zero. 167 00:11:13,920 --> 00:11:16,510 So we're getting just the base salary. 168 00:11:16,530 --> 00:11:16,850 All right. 169 00:11:17,190 --> 00:11:19,250 So let's add an additional rule. 170 00:11:19,380 --> 00:11:19,890 All right. 171 00:11:21,120 --> 00:11:33,030 The boss, the boss said that the first employee, Sal Index zero does not. 172 00:11:37,080 --> 00:11:37,800 Listserv. 173 00:11:46,030 --> 00:11:47,050 Any bonus? 174 00:11:48,100 --> 00:11:51,290 All right, so he's not a good worker. 175 00:11:51,460 --> 00:11:53,050 He does not deserve any bonus. 176 00:11:53,410 --> 00:11:59,740 So we're going to also add here an additional additional topic we say here if. 177 00:12:01,140 --> 00:12:14,770 Police equals zero, do nothing, and if it's not zero else, do the formula, by the way. 178 00:12:14,790 --> 00:12:18,210 I don't know if I mentioned it with using the tab key. 179 00:12:18,230 --> 00:12:23,470 You can go with the intention and using the shift, you can go backwards. 180 00:12:23,520 --> 00:12:23,910 All right. 181 00:12:24,700 --> 00:12:26,750 So this is how we're going to get it. 182 00:12:27,360 --> 00:12:27,810 All right. 183 00:12:27,840 --> 00:12:34,170 So if the place is zero, don't do anything because the boss said that the first employee does not deserve 184 00:12:34,170 --> 00:12:35,010 any bonus at all. 185 00:12:35,460 --> 00:12:37,080 All right, let's run it. 186 00:12:38,940 --> 00:12:45,780 All right, great, so we can see the one thousand value is removed from here and we have applied all 187 00:12:45,780 --> 00:12:49,080 of these rules upon this example right here. 188 00:12:49,800 --> 00:12:56,880 So you can see here and this example perfectly, how can several topics can be combined and a very smart 189 00:12:56,880 --> 00:13:04,650 way into formulas, into some things that help us in life, or even if you're going to become a web 190 00:13:04,650 --> 00:13:10,230 developer or an information developer or backend from 10, doesn't matter what you can use all of these 191 00:13:10,230 --> 00:13:13,710 items to structure yourselves whatever you need. 192 00:13:13,960 --> 00:13:23,010 And right here you can see collections for loop if statements, past statements, and you can see all 193 00:13:23,010 --> 00:13:24,090 of them combined. 194 00:13:24,120 --> 00:13:24,500 All right. 195 00:13:25,140 --> 00:13:30,410 This will be the end of the advanced part in the next lecture. 196 00:13:30,420 --> 00:13:34,790 I will go over the assignments and also the lecture after it. 197 00:13:35,280 --> 00:13:38,550 As always, I will show you the answers for these assignments. 198 00:13:39,100 --> 00:13:41,700 I wish to wish you good luck with the assignments. 199 00:13:41,800 --> 00:13:43,290 I will see you in the next video. 200 00:13:43,590 --> 00:13:44,070 Thank you.