Hello everybody.
And welcome back.
In the previous video.
We saw how we can use the if l statement in our program.
Now let's see another statement that we can use which was the false statement.
So it basically says as it basically does as it says.
So for something do something.
Now the basic use of this would be so let me open up my Python interpreter.
The basic use would be or what we will use most likely is for something in range of a few numbers.
So let me just show you what I mean.
So let's say no equals 1 and then we want to do this command right here.
So for AI or basically for anything for AI in the range of range is basically an inbuilt function.
So in range 1 comma 10 then we close the parentheses then two dots.
So let's first explain what this means.
The range is basically it is saying for some AI variable in the range from 1 to 10.
So this I will take the values from 1 to 10 do and then your presenter then tab it so we can push it
forward and just type here.
No equals no plus I so let's press here enter enter once again and if I just could not type number once
again you would see that our number is now forty six.
Now if you did not understand this you are probably all you're probably ask yourself how is the number
right now 46.
So let's take our in-depth view on this right here.
So we first specify our number to be 1 then we specify this right here.
So for i in range 1 2 through 10 do number equals nine plus 1.
So for the first for the first circle of this command I will be equal 1.
So it will then do.
Number which is 1 equals number plus I.
Which is then 2 so number is 1 and I is 1 in the first circle.
And then our number will become 2.
Then it will go back and then it will do that.
The AI is now 2.
So since we already did 1 and now it will be two.
So now this will be two equals two plus two.
Since our IDE is now two or one plus two.
Pardon me.
And then it will do it all the way through 10 and then it will give us the output of all the added numbers
together of which is forty six.
So that is how the for loop works.
Now let's see how we can also use it in order to for example increase all the numbers in the list.
Now we didn't really cover the list yet but just type what I do so let's make our third program.
Now I know Python 3 but by we specify the path I will not say why anymore since I did it already twice.
And right now I have to specify the path we want to print to make a list.
Now our list is basically a list of different strings or different numbers.
In our case we will use a list of strings so no underscore based.
We'll call it like that.
You can call it anything you want and we specify lists with these brackets.
We do not the normal brackets but with these brackets right here and then we specify the numbers in
our list which would be 1 2 3 4 5.
And then we close the brackets.
So this is how you specify a list.
You can put any numbers here you want divided by the comma.
And right now what we want to do is use our for loop in order to for example increase each number from
list by 1.
Now how do we do that.
Well it's a little bit different.
So do most of the commands is actually the same.
So what we want to do is for i in range and we want to open up our brackets but not type here the range
we want to type your length since we want the length of this list right here to be the range of our
loop.
So for I enrage and then open brackets Len with 10 which stands for Len and then the length of our number
list.
No list then we need to call those two brackets and then put these two dots right here so this basically
says for any number or not for any number for some variable i in range of the length of number lists
we want to perform the number list
of I plus equals 1.
Now I will explain what this does in our future lectures for non.
Just trust me that this will actually increase the numbers in our number list by 1.
And if we printed the N number list
and save this.
So control X to exit c h mode plus X in order to make it executable and then we run the Python 3 you
will see that I did the number list is no longer one two three four five.
It is now two three four five six.
So basically that is the simple use of the for loop.
Now don't be worried about these lists right now.
We will cover lists later on for now.
I just want to show you what this can be used for.
So for example if you had a list that is too large you could with this simple two line code change the
values of all of those numbers in the list or in basically in our case increase them by 1.
So for loops and if loops are very useful you will also see in the next videos Why yes.
I basically only show you some of the most basic examples.
They can be even more useful than this but for now on this would be enough in the next video which will
cover a while loop that we will also use in our backdoor program.
Well actually that is the most important book since we can specify some pretty pretty good things with
it.
I will show that in the next video and I hope you enjoy this one and I hope I see you in the next video.
So take care.