Hello guys and welcome back to another class of our course about Python.
So in this class we are going to talk once again about a very important thing in Python programming.
And this is the while loop.
So in this what what exactly is this while loop.
What exactly is a loop is if for example you want to run a code a multiple amount of times.
So let's say for example I want to run a quote code until a certain outcome have been reached.
So let's say for example I want to reach a certain outcome I'm looking for a certain password for example
this can be used in cybersecurity so let's say I want to make a brute force attack and I want to crack
a password.
So in this case I will run many passwords.
I will run many combinations until the right combination I have has been let's say achieved were the
well python have achieved the right combination.
So this is exactly what we are going to learn today.
You can use this well in that analysis you can use it in many many fields.
So this is an important function.
Once again it's not hard to understand once you'll see what it looks like.
So let's start so the first thing we want to do will be have variables.
So in this case we need to choose at least one variable and the let's say our variable will be.
I don't know.
Let's name it variable in this case is going to be variable one.
All right let's say variable one will be equal to let's say twenty five and we'll have another variable
which will be variable too so variable one and variable variable two will be equal to let's say 2000.
All right.
So we run a very very simple code.
So in this case we want variable 1 to be greater than variable 2.
So how we write this or let's say you write down well and in this case you write down your condition.
So let's say variable 1.
This case is greater than variable to
so here we go.
So until this condition is met the code that is here will be replaced.
So until this condition is met the code will be replaced.
So let me show you what it will look like.
Let's say for example we want to print.
We'll print our variable one.
So we'll print two things we'll print viable one
and as well as we'll print let's say doesn't work
we're not good
all right.
And what exactly will be will be making as a calculation to in this case if we only print the variable
one it will not make sense because what's going to happen is Python will run only this code and it's
not going to change.
So if we run our code as you can see it doesn't make sense.
It will run until the infinite.
So it will just run this code but it doesn't make sense because variable one will always be smaller
than variable too.
So let's thing let's say we want to add a calculation to what our variable.
To group.
So in this case let's say variable 1 will be equal to via variable 1
plus let's say 5.
So what the what this means.
This simply means that we will run our courts will have our variable one.
In this case it's 25 the first time.
So what's going to happen is that python will run this code.
So the first time that he will run the code variable one will be equal to twenty five.
Then he will also print not good then variable one will be equal to variable one plus five.
So once again variable one will become 30.
In this case variable one becomes 30.
So once again python will verify here.
So here we have 30 30 still less than 2000.
So we are going to rerun the code.
And right now what's going to happen is variable one is 30 so variable one is equal to variable one
plus five or 30 plus five.
It's gonna become thirty five.
So just look at the code and you'll see what exactly is happening here let's say we run our code once
again and as you can see that's exactly what's happening.
Each time the code is growing by five.
And at the end it's reaching one to one thousand ninety five nine hundred ninety five.
So until the moment that variable one is smaller than the variable to the code will continue to run
but when it's reached at the end it's gonna stop running.
So in this case it stopped running at one thousand ninety five hundred because the next the next jump
the next it's in the next moment the variable one will be not greater but will be equal to variable
number two.
And this is why Python stopped at one variable list.
Let's explain it has many many utilities in let's say in real life and this type of what this function
is very very use that same cybersecurity if you want to for example crack passwords it can be used if
you are looking for a certain output somewhere and you need to try many many things.
Well it can use this function and once again you can write anything you want here.
So let's say you hear it's just something that is very very simple.
Once again you can write as I said very very complicated functions right there.
And python will still run them until you have the output that you need.
Exactly.
So let's say you can change your variable to buy something else let's say you want to change it by 1000.
In this case you want to change it by 1000 and we can just run our python and as you can see it's going
to still work.
So as you can see it's something that is very very cool.
And once you know how to use it properly with all other functions you'll see you'll be able to do many
many very interesting things with it.
So that's it for this class.
Guys in C in our next class.