Hello, everyone.
In this particular session, we would be discussing about follow up on Vinu, so first we need to know
what is actual need of these moves and what are loop's.
So here I have a piece of code where I have created a list of names.
So I have address John Tokyo and Berlin.
Now let's say you want to display the names one by one and we want to say hello, hello.
Hello, hello, Tokyo.
So let's just run this.
So here, if you see the outrage over this entire list and we are taking one index of the list at a
time and then trending this now while doing this entire thing, first of all, I had to type all the
lines of code again and again.
And I have just five lines of code, which I had to write here.
So it was a little simple for me, but let's say instead of these five means, we have five hundred
names.
So in that case, would it be feasible for me to type in Palo and then names again and again?
Five hundred names?
No.
Right.
It would be pretty difficult for us.
So this is where we need four or you.
What this actually helps us in, so here we are able to iterate over a particular object, so that could
be a list.
It could be a string.
It could be range.
I'm and I read on top of it.
And we can use one item out of the entire sequence, one by one on this play or whatever action we want
to do.
So here what we can do is we can trade over the sequence means.
So when we will agree to work, we will get the name Horia first, then we can print it.
Then the next value would be SANZAR, so we can trade on top of it.
So let us see, what is this index for that.
So this index for Falu would be for.
Then we write.
Obviously, you've seen me.
In names, this is the list which I want to I try to wear so I would see names.
Then I give the Colin.
I hit enter and the automatic indentation comes in, so again, just like if as we need to provide information
in for loop also, so we will provide this indentation.
Now, this name is just a very boobage I have created.
I can give it any value.
I can give it IGP or any other name or some name, any kind of variable could be created.
This does not this is just a dummy name so we can give it anything.
So I will use name now.
I will just say print.
And.
I will say hello.
Space.
And I would say name.
And.
One said on this, I get the entire thing again, so instead of writing the lines again and again,
I can do the same thing by just writing a single line of code.
So this is what Falu provides us.
So let us see, what do we have here?
So the for loop, I agree to a sequence of items and runs a statement for each item.
Once the items are exhausted, it stops the loop and runs the next line of code.
So it would stop it.
Would it read over an entire sequence and pick out the items it will best?
That is the sequence.
And so if the sequence is not and B we still have some items, then it will run the statement book and
then go back to the for loop and figure out the next element in the sequence.
It will decide if the sequence is empty, then it will get out of it, otherwise it will keep iterating.
I'm doing this.
We exhaust all the elements which are present in the sequence.
This is how for Loop works and we have seen the syntax for it.
Now let us see what type of values of all look inside.
So first we will look for a string.
So it does have a spring save for.
I do or see.
Gary.
And let's give any string my.
My name is.
John.
OK, this is the string which I have and.
I would simply say the same thing.
Brent.
Gary.
Plus, let's see anything, let's say one, two, three, OK, so we can run this and it will just stay
and display whatever we wanted related to what each and every character of the string.
Why is it trading on each and every character of the string, as you already know, a string is a sequence
of characters.
That is the reason why it was able to I on top of these.
Now, I can give any number of code of lines here.
I can see friend one plus.
To then it will again do this, I can have another look inside this.
For, let's say.
I am.
Hi, and then we save print.
So if you can see we are nesting the for loop again, so we'll just rent I, I.
Let's see.
So it is printing the character first, the character plus one, two, three.
Then it is printing this three which we have made a before and after that does it reading on top of
the characters in high.
So it does printing etch and then.
So this is how we can it on top of characters of a string.
Now we have already seen how we can iterate on top of elements in the list.
Now let us see how we can I trade on numbers on predefined numbers.
So let us see.
First of all, let me introduce range to you.
So for.
Well, in range.
So I'm running this on range then, and I will simply print the world for you.
So here you see.
The value is being printed, so it is trading on numbers from zero to nine.
So if we give range then so it will go from zero and the split in values.
Now, let us see.
We want to start from let's say.
Twenty and more than.
Twenty five.
Then here it is.
Now, let us say we want to skip a few numbers in between so we can give the step function also here
to simply walk like the slicing, which we have.
So it is simply like slicing.
We give the starting point, then we give the last value minus plus one.
And this is a step function.
This is this.
Now that is one more thing which we need to include, which is including continue.
So let us see how we can continue.
So let us say we are working on.
This particular.
This particular look, now let's do one thing, the letters include a new value here as count.
And.
We made this count as zero and after each law.
We will change the value of pound is equal to pound plus one, so we are increasing the value of pound
after each iteration.
So let us do one thing now after this.
Let us bring county instead of this.
OK, now let's check a condition for an itch, so.
Sound is greater than, say, six.
Then we are doing all.
Continue.
Now, what continue does is that whenever we encounter a condition, whenever we encounter continue,
then it will not run these lines of food and it will simply go back and.
Continue with the vibrations.
Let me do one thing, let me please the council before.
Continue.
So let us run this.
So here what happened is it is trading on the perfect.
So.
It has not increased the volume.
Now, let me put it above that if condition.
And let us keep it till three for convenience.
So it is printing and then it is having volume zero down, volumes one, this is two, this is three.
So when the pound value is three.
This is here, the ground value becomes three, so it will check that its value is greater than three,
then it will continue.
So it is not printing high after this.
Now, let's say they don't want to bring these values, also, we just want to break the loop and come
out of it once the value of golf is greater than three.
So instead of writing continue, we can simply write, break and dig the new.
So here it has written for us.
Now, let us discuss about why you saw the difference between four and why was that in case of violence?
We are tripping on top of an entire sequence, but in case of violence, we see why and devalue the
particular conditions.
The account is less than five.
Then he wanted to do something, then we wanted to.
Brent.
The value of count.
And after opening day, we wanted to update the value of ground.
Let me we sure initialize the value of found.
So here.
We are running this, so it will start with ground value as it evaluates the value of so here the value
found is less than five.
It brings the value of ground and updates the value of found to and then again, it goes back.
It checks that the value of gold is less than five and it keeps doing that until the account value is
equal to five.
So this is what value looks like.
The index is just the same.
So we see why.
Then we give the condition and then we give the colon and we give the indentation.
Similarly for for loop the give for the give the items on which we want to intrude upon.
We give the sequence, then we give the sequence details that it is a range or if it is a particular
list of characters or if it is a list, it says.
So this is how life works now, apart from this vital condition, we can also have white ants in other
languages.
We do not have the option of else, but could increase survival.
We also have violence.
So let us look at the.
So for Vilo, it repeatedly executed a bluff of food indefinitely a number of times and until the human
condition becomes false.
So here we were checking the condition that this count is less than five.
And once the condition becomes false, it comes out of the way.
You now, invitingly, can add an optional clause after the end of the view.
So we can add as fills the code inside the as clause would always run.
But after the you finish execution, the one situation when it will not run is if the loop exits after
a break.
Stay tuned.
So let us go back to let us add is the mission.
So is why golf is less than five.
It will bring this, it will update the calendar and then the goal is not less than fine.
It will print.
The very influential.
So this so it initially ran the ground, it didn't run from zero before that, and after that it will
run the S.T..
Let us make the value of count is equal to five.
So in this situation, the count will be equal to five, so the condition will not satisfy and this
will never become to equal that.
It'd be false.
So let us try this one.
So here the number is greater than five.
The value runs.
It is a false condition.
So it does not run this be supported by Tehran and its condition.
So this is what VIU is.