Hi, everyone, and welcome to this lecture, and as I promised in a previous video, I will now go
over the examples of for loops the advanced sport so you could get the hang of it much easier.
So once you open your project, just create a new file and you can call it for loops, advanced examples.
And first of all, what I'm going to do is just leave a note here for loops advanced.
Examples and the simple thing I'm going to do is going to copy the examples already had from our PDF
to here, and let's go over them quickly.
All right.
So this is the first one between them.
I'm going to leave print quotation marks and you can see it's marked with orange, and that's because
it's a saved character.
If you recall from previous lectures, what it does actually what it does, it just leaves us a empty
line so we won't get mixed with the examples.
All right.
So what we had in the previous video, we had these three examples.
All right.
And let's run it.
OK, so the first example right here, we're getting numbers out of the range function and starting
from zero and increasing by one on each iteration.
So first iteration gets zero.
You see printout zero right here.
Then in the second iteration, it's plus one.
So it's one.
So printing number one right here and so on and so on.
Until we get to the limit, the limit is six and the maximum limit is excluded.
So you can see number six is not in the printout right here.
And in the second example, we're seeing minimum maximum limits, same logics starting from three now
and printing it then going plus one each time until we get to the limit.
And in the third example, these are the minimum and maximum limits and we're increasing by three on
each iteration.
So we can see here three then plus three in the second iteration, it's six and then we have nine and
12.
The last number is excluded because as we discussed, the maximum limit is excluded.
All right.
So from here, you can ask yourselves, why the hell do we need this range, range, method?
All right.
So we want to sound smart.
We don't know new things, talk about it in interviews and stuff.
But what is it good for?
Actually, let's talk like real life.
Why do we need it?
Because it just gives us some number.
So what can we do?
It is we can maybe, like, multiply by ten, for example.
Let's run.
All right.
So you get multiplied by ten.
But what can we gain from it, actually?
All right.
What can we gain from this?
So I'm just going to show you a quick example is going to erase all of this and leave the last example,
which is the third from the previous video.
I'm just going to maneuver it a little bit.
All right.
So I'm going to show you that you can do lots of interesting things with this range method.
OK, so first of all, we have seen in the basic lectures regarding loops, we have seen, for example,
that we had fruits.
All right.
And we had banana.
Jerry, don't recall if it was in this order, but it doesn't example, it doesn't matter.
And then what we did here, we just copy and then placed it right here and then we ran each cell each
time and then we could, like, manipulate this and whatever we want.
But we ran over these cells one by one, and it had some meaning or because we can control it.
But in this example, we're just having some numbers.
You what can we actually do with them?
All right.
So instead of having fruit here, I'm going to show you an interesting example.
Right.
So imagine yourself that you work in a company, you work in accounting, and your boss doesn't have
a clue in coding and he gives you some guidelines for bonuses.
All right.
Like this gives you some guidelines.
All right.
And in these guidelines, he give you several rules.
All right.
He says to you, I want you to build a formula for Yula for bonus bonuses.
All right.
Employees are placed in cells by their work ethic, meaning some of them work hard, some of them do
not work hard.
And he doesn't want to tell us actually specifically the names and he just place them in certain places
inside the list according to their work ethic.
All right.
He tells us that we give each employee.
Implore e a bonus, which will be based on his place in the list.
Multiplied by 100.
All right, multiplied by 100, meaning multiply this number by one hundred, and this would be his
bonus.
All right.
So place multiplied by a hundred.
This is the bonus.
All right.
And the boss said.
To give bonus.
By jumping plus three each time in the list.
All right, so just going to make a quick list of salaries here, and it's going to be one thousand
to three for all four thousand, five, six, seven, eight and nine.
All right.
These are the salaries.
Some of these employees work hard.
Some of these did not work hard.
And the boss wants to give them bonuses.
He does not want to tell accounting.
What are their names or something.
Right.
Just a discrete bonus plan.
Right.
And now he wants us to do the following thing here.
I'm going to place the numbers zero to nine because we have sales zero one, two, three, four, five,
six, seven and eight.
And right here we had the same number because remember that the number nine is not included once we
run the loop.
So basically we have eight, eight iterations here.
All right.
And also we have applied bosses rules to jump by three each time.
This one we'll call it place or right place because we call it place right here, Blayse and in here,
which is going to go for we're going to go for the formula.
So we have here salary.
With bonus like this, and we're going to do the following thing, we're going to extract extra values
out of the list by their places, so we're going to put the place because police is basically just a
no.
All right.
Place is basically just a no.
It's just a no out of this range method.
So it start with zero.
So if you put the number zero here instead of zero, what does it stand for?
It stands for this value right here.
Right.
But now I'm going to use the workplace instead of zero because I want it to change in each iteration,
because if I leave it zero here, so in the first time, it will be this this guy in the second time,
it will also be this one and so on and so on.
It will always be the first cell.
But I don't want it to be always the first cell I want wanted to change.
So I'm putting the place here so it would get numbers.
The place will get numbers out of the range method.
Right.
And this thing I want to this is like the basic salary.
Right?
These numbers are the basic salary base salary.
Want to added are place multiplied by hundreds.
Right.
This is what the boss said.
Right.
And then I just want to print it out.
All right, so print are salary with bonus, I think we got it right, let's run it.
Great.
All right, so we started off with this one, and for some reason we're seeing here a small problem,
right, because these two numbers seems to add up, right?
Because we can see here, we're starting from here, right.
Then we're jumping three.
So this is one to three getting here and here.
The number is three.
All right.
So we're getting four thousand.
Four thousand three equals one thousand.
So this is three thousand plus four thousand.
So we're getting seven thousand.
This is great.
All right, then from here, we're jumping three, one, two, three.
Getting here and here the number is six.
So we have six thousand plus the base salary, which is seven thousand, which is this one.
So six thousand plus seven thousand sums up for thirteen thousand.
But here and the first cell right here we're getting 1000.
Seems nothing happened here.
Right.
But remember that this Scelzi index is zero.
All right.
So this thing this thing comes with zero because zero multiplied by one thousand is zero.
So we're getting just the base salary.
All right.
So let's add an additional rule.
All right.
The boss, the boss said that the first employee, Sal Index zero does not.
Listserv.
Any bonus?
All right, so he's not a good worker.
He does not deserve any bonus.
So we're going to also add here an additional additional topic we say here if.
Police equals zero, do nothing, and if it's not zero else, do the formula, by the way.
I don't know if I mentioned it with using the tab key.
You can go with the intention and using the shift, you can go backwards.
All right.
So this is how we're going to get it.
All right.
So if the place is zero, don't do anything because the boss said that the first employee does not deserve
any bonus at all.
All right, let's run it.
All right, great, so we can see the one thousand value is removed from here and we have applied all
of these rules upon this example right here.
So you can see here and this example perfectly, how can several topics can be combined and a very smart
way into formulas, into some things that help us in life, or even if you're going to become a web
developer or an information developer or backend from 10, doesn't matter what you can use all of these
items to structure yourselves whatever you need.
And right here you can see collections for loop if statements, past statements, and you can see all
of them combined.
All right.
This will be the end of the advanced part in the next lecture.
I will go over the assignments and also the lecture after it.
As always, I will show you the answers for these assignments.
I wish to wish you good luck with the assignments.
I will see you in the next video.
Thank you.