Hello, everybody, how are you?
Now, we have completed the Four Loops series and we have seen lots of examples, I think that we are
ready to study its twin brother in for loops.
We have seen statements which helped us to sort of lead the code inside in Eve or inside itself.
And we were scanning lots of variables or collections with the hand of the for loop and applying some
actions upon the cells of a collection.
So while LOOP is a bit different, let's start from the top and see the difference between the two loops.
All right.
So a take Python programming language repeatedly executes the code inside it as long as a given condition
is true.
So you can see right here that we have sort of condition once we declare while we didn't have it in
for info Oprah just mentioned, what do we want to scan?
For example, we have a list or we have a range, meaning we have certain number one, certain times
the loop that will run.
But we didn't have any condition, like practically we didn't could not declare a certain condition
that we want.
So in wireless, we do have it.
So let's see quickly the differences between for and while loops.
So we have seen that for loops we're scanning in sort of speak collections or variables one by one.
Then after we were focused on a certain cell or some other variable, we added and if statement that
could apply the upon the code inside the for loop, we had an if statement and each cell in our examples,
we could determine what to do with it, like whether we want this element to apply a certain action
or simply go to else and do not apply any action.
So we had an, if else, statements inside the follow up.
This is what helped us to navigate the code inside the for loop in while loops.
It's a bit different in Y loops.
We mention a condition right where we declare the loop.
OK, so once we declare that we have a wire loop, we have a wire loop right there in the same line,
we declare a certain condition what we didn't have in for loops in four follow ups.
We had some conditions, some statements inside the fall.
But right here in while loops, we declare a condition right where we declare the loop itself.
And as long as the condition is true.
We will keep running cycles upon the fire, upon the wire.
What that basically means, we'll have cycles going again and again as long as this condition is true,
OK?
We've seen examples and example in a few seconds.
OK, so the simplest way we can create a variable, just simply create a variable and you can call it
no equals zero.
This will work as our counter, basically.
In other words, this will be the condition that we will check in every cycle of the wild.
OK, so then we define a wire loop with a condition.
The condition is the following thing.
As long as no is smaller than 10, continue running.
OK, so the beginning number equals zero equals zero.
You can see where my mouth is.
So number equals zero.
Then we declare here a while.
This is the key word for a while loops and then we set the condition in our in our example, it's no
smaller than ten, but for now number equals zero zero.
And if we run this cycle, this while loop again and again without growing our number, a variable number,
if it's just stays zero.
So it's an endless loop and can cause lots of trouble for our programmers, for programmers, whether
they're web developers or back in front, it doesn't matter.
Once you have an endless loop, it gets stuck in the whole system.
Your whole computer or your server can break down because you had an endless loop and can crash your
systems.
All right.
So we can't have this we can't have an endless loop in our code.
And what we are willing to do, you can see the dots part right here.
OK, so right here at the bottom, we have no plus equals one.
OK, number plus equals one.
What that means is what that means is, is basically this thing the same thing number equals number
plus one.
What you seen in the in the here in the example, in the code example the number equals the number of
plus equals one is just a short way to write this thing.
OK, number what we have current value growth by one.
OK, so just going to erase it.
So what we want to do.
OK, ok.
This part with a dot, it's inside the wire loop so each time the will run this call in the dots will
be executed.
So basically what we're saying here is each time you run the cycle, grow the variable number by plus
one.
So we start with this with zero and we get here.
Here we're seeing growing by one.
Then we go to the top again to the wild condition.
OK, now the number, the variable here, it doesn't equal zero like we're declaring it.
No, we have grabbed it by one right here at the bottom.
So right now, number equals one already.
So we execute the code again and again.
Again and again.
Up until the fall of the wild condition here would be false.
Or in other words, as long as it's true, it will run again.
So once we get here to 10, once we have here nine plus one and we go again to the top on the 10th cycle.
So we'll have your number smaller than ten, which is ten, smaller than 10 once.
This statement will be false.
It would be a light.
The code will exec exit the wire loop and go with the flow of code.
What we have after the wild, it will exit the wild completely.
So just want to just want a market once the value here would be ten.
OK, this would be a false statement and then while Loop will be exited.
All right.
So that's it.
It's plain.
Simple.
It's not very hard.
Once you understood the four loops, this is piece of cake.
You just have here a condition.
You can set it here, whatever you want, whether a number or a letter or doesn't matter.
And as long as this statement right here is through the cycle, what under the wire loop will keep running
again, as will go from the top again and check the condition and run to the bottom and then again from
the top and so on and so on.
And you have to find a way to stop the while loop so it will not run forever.
And this you do by changing variables inside the content of your while loop.
So that's the theoretical sketch, for example, for for a second to see what we just seen here.
So basically just start the module with a while.
For example, you have a certain module that you have only a while openside.
So you start running the module and then you get to a condition of.
That while loop in this condition, we check if the statement is true, they called on their while loop
will run and then you go again to the condition to the top.
Then again, the condition is checked.
If it's true, it will run again.
OK, up until the condition would be false.
Once the condition on the top would be false, the cold will exit your wirewood.
That's it.
Plain, simple.
I think this theory covered the basics of a wild pretty easily.
And you can see an example here to apply the rules.
As we just discussed, we will go further to the next lecture by seeing advanced dance characters off
while loops and also live examples as well.
And right after we go to the practice part, I don't worry about it because it's pretty easy to understand.
Once you once you get once you get the rule here and this is just mentioned, you will see many examples
in the next lectures.
And I think that you could get the hang of it.
I'm sure of it.
And that's about it.
I think we closed up this lecture the next one.
Thank you and bye bye.