Hi and welcome to all of you, and today we'll continue discussing for loops and once we've covered
the basic theory in the previous lectures, I think it's time to head off to the advanced topics.
And also an important note.
Don't worry if you find this lecture a bit challenging and a bit hard, because, first of all, we're
an advanced stage stages and for loops.
And also, I promise you that in the next video you will see these same examples, these same topics,
live and patient life coding.
And I will apply them in my term and also going to explain them thoroughly again.
And I'm sure that you're going to get the hang of it once.
I'll explaining once, twice or three times.
It's nothing complicated.
After you break it down into small pieces.
Everything is easy.
Trust me on this one.
So you will see these exact examples in the next lecture as well with small modifications and you will
see how can I apply in life coding on Pichon?
All right.
So let's find out what these the range function and how to use it with loops.
So to run the loop for a specific, specific number of times, we can use the range function, which
basically will pass the loop a sequence of numbers.
All right.
So the only thing that the range function does, it passes a single number on each iteration of the
loop.
It passes a number to the loop.
That's it.
So this is the basic rule.
And we have like the basic functionality of range.
And we have also some interesting features that are optional to use with the range.
So let's go all let's go over all of them.
All right.
So by default range function will start with a value zero and increase by one on each iteration and
we'll stop at the limit that we have set for it.
All right.
So let's see an example right here.
Example, a start from zero and then increment by one on each iteration.
So as we just mentioned, by default range, we'll start with the default number zero and we'll increment
by one on each iteration.
Notice in our example, six is not included.
All right.
So six is the maximum limit and is not included in the output.
So you can see a for loop right here.
And what basically happened that we don't have, like the structure that we have seen for in the previous
lecture, four x, four X, I wanted to be with small letter for like cell in list like this.
And here we have the list, for example, with one, two, three, four, five.
It's not this case.
All right.
So the list is the whole, as we discussed, and one cell is each of these items.
So now we're not having this thing.
We're having four X in the range six.
All right.
So the loop will the loop will get numbers out of this function.
And the first number would be zero from here.
This is again, this is the hole, as we have seen right here.
The least is the hole.
So in our case, the range function is the hole and it will pass a number on each iteration in this
case starting from zero to this X-ray here.
All right.
Again, this range function will pass a number on each iteration to this X right here, starting from
zero for the first iteration, then one, and then the second iteration, then two in the third iteration,
four and five.
And that's it.
All right.
And then just to check how it works.
All right.
So what we have done right here, which is going to bring this X, right?
So in the first iteration, we're going to get the zero here.
All right.
So we're going with the loop.
We're getting zero and then we want to print print that X.
All right.
So this X in the first, first, first iteration, it is zero.
So it's printed right here.
Then in the second iteration, it's one third duration is two, three, four and five and six is not
included.
Six is the maximum limit.
So it goes zero, one, two, three, four and five.
And then it stops, then the fall, then the called X is the follow up and goes further in the code
down.
All right.
It's not pretty.
It's not it's pretty easy, actually, if you think of it right.
Each time we get one number out of here, starting from zero going up plus one on each iteration.
That's it.
Basic and simple as that.
From we're going to go one level up and we will see example be first of all, let's read here the second
both.
It's optional.
As you can see, we can also give a start and end limits, too, for the range function.
All right.
And tell it on what number to start and on what number to end.
So in the first example, it start by starts by default from zero and stops at six.
All right.
But now let's see how we can set it a start and end numbers.
All right.
Also, like an example, a in this case, the number the number will increment by plus one on each iteration.
OK, so it looks like this.
You see right now we're having two numbers inside the brackets and these two numbers are stating the
starting point and the end point of the loop.
So in the first iteration, this is going to get the number three and also we're going to print it out.
Obviously, the second iteration, it will before it will be printed, then five and then six.
Also, like in the previous example, the maximum limit is not included.
So the maximum limit here is seven.
And as you can see in the output, we would not see the seventh number.
It's not included.
All right.
So this is a starting point.
This is the end point.
And each iteration will be increased by plus one.
All right.
This is an example.
Now, let's go to bullet number three.
Additionally, we can also pass the rate, the range method, the incremental margin number for each
iteration.
OK, so in these two examples, we have seen incrimination by plus one on each iteration or each cycle.
Each cycle of the loop was increasing by plus one.
Here we have zero, then one, two and so on.
And here we started at three, then four, five and six.
Each iteration goal goes was plus one.
But here and this example.
All right.
We can give the third number inside the brackets right here.
All right.
So here we have the starting point.
Here we have the end point.
Same as we had an example.
B is right here.
We have the incremental number, meaning it's each iteration, each cycle would be increased by three.
OK, so then we're going to start a three right here.
We're going to print it.
Sorry, it's it's not the correct numbers, so we're going to start let's make it a bit smaller, so
will we be a bit easier like 12 or.
Right.
So we'll start with three, then we have six, then we have nine.
And then we have 12 while 12.
As before, not included, so I'm going to erase all of these numbers right here, because always the
last the maximum range is not included.
So, again, let's explain it again.
We're starting this is the starting limit.
This is the end limit.
And this is the incremental number like plus what number we're going to give on each cycle.
So we're starting with three, meaning this is this is what we get right here in the print.
So in the first cycle, the print will be printing three.
In the second cycle, we're going to get the last three.
Right.
So you're going to get six here.
And then in the third cycle, we're going to have nine, all right, and then we're going to have the
fourth one because our limit is 12.
But like always, the maximum limit here is not included.
So this would not be inside the print.
OK, this is as always, so the maximum is not included.
Samia's here you see that seven does not appear in the output.
This is the rule.
All right.
So it's not very complicated.
You have three examples here.
Feel free also to use the PDF attachment file to read over the material.
And I will see you in the next video where you see these examples live in Pichon.
Thank you.