Okay, now you know how to use condition.
Let's go, uh, learn loops.
Okay, let's create a file.
Loops.
Dot py.
And Python has two primitive loops.
Command.
Okay.
One of them is while.
Let me write that here while.
And the next one is for.
So we used a for loop before.
And you know a little thing about for right now we are going to learn while loop now and for loop in
the next lecture.
So while loop with the while loop we can execute a set of statements as long as a condition is true.
How?
Let me give you a simple example here.
Okay.
Just imagine x or I is equal to a number which is one okay.
Now let's use while here give a condition okay.
For example right now I am printing uh this I as long as I is less than a number, for example ten.
Okay, so I say I less than.
Now you know how to use less than okay.
Less than a number which is ten.
Okay.
In here let's print an I.
And then in the next statement in the next line you need to increment I by one.
Okay.
So how can I do that.
Very easy I say I plus equal to one.
What is this mean?
This means each time that this one is repeated, increment this I by one.
Okay.
Or we can do this in another way as well.
I can say I plus.
One.
Okay.
This is one way that we can do.
And also this one is another way.
Let's save it and run this program.
Now you see it is giving me from one app to Two and nine.
Okay.
And here it's not giving me ten, because I am telling the condition that it needs to be less than ten.
If I use less or equal, then it will give me number ten as well.
So that is how you can use and how you can use while loop.
And also we can use another statement that is called break statement.
With the break statement we can stop the loop even if the while condition is true.
So how.
Let's go and see that as well.
Right here inside this I can use an if condition before we learn something about if condition.
Now you know what is that mean okay.
If I is equal to three for example then let's break.
Okay.
While we are using if condition here, we need to give colon and be careful about this space okay.
And right here let's use break statement.
And now save this Execute this.
And you see we have only three number here.
Why?
Because I used break statement right here.
And also there is another statement that we can use with while loop that is called continue with the
continue statement.
We can stop the current iteration and continue with the next one.
Okay.
Right here instead of break right now if I use continue it will do something.
Let's see.
Continue and save this now.
Actually not right in here.
Let me remove this part and go from the beginning.
Okay.
Hit enter.
Now let's say I is going to be incremented by one.
And if this I is equal while we use two, equal means equality okay.
But if I use one equal that means assigning.
So if it is equal to three then let's say continue New.
And here let's print this number which is I right now.
It will start iterating okay.
True.
And checking for the if condition.
And if this I is equal to three.
So it will not print it and go for the next uh condition.
Let's see.
Right now we have one and we don't have one okay.
We have two and then we have four.
Let me change it to another number for example seven okay.
Now let's see that.
Okay.
See we have 23456.
And we don't have seven right in here okay.
And then we have it.
That is because of this continue keyword or continue statement.
As you see here we use if condition.
And also we can use else condition as well.
And that is very easy okay.
You know how to use it.
So thanks for watching and I will see you in the next lecture.