Hello, everyone. And welcome back to enter the python here on cyber. Very on demand.
As always, I am your instructor, Joe Perry. I'm going to be running you through today's lesson, which is less than three while loops in Python.
So less than three. We only actually have one objective. It's a very straightforward objective. We're going to learn to use wild loops in python,
the reason why we only need one objective. The reason why this is slightly shorter lesson is because of the fact that we already kind of covered the constant condition ALS and looping in our previous videos. So here we're just learning about a new implantation of that. We're gonna change to the correct lesson folder,
which I believe is less than three. Yes, listen, three fantastic.
When you record videos for 12 to 14 hours a day, it's released you to forget where you are.
So we've got less than three, which did not update at the top of the screen. And that's just gonna bug me the whole video. And now because I drew your attention to it, it'll bug you to welcome to this
wonderful, glorious pain. Anyway, back to the lesson Python three.
We open our interpreter here. Now you'll remember that if we do some if conditional,
with four, we did four conditions
code. While Luke is gonna be much like a statement, as we talked about in our looping lesson when we're just talking in the abstract, it's very similar concept of
it's basically just evaluating some bullion value here.
with four loops, you were able to do four
with a while if you can't quite get away with that, because of the fact that the Python interpreter does not automatically know to insert some information
into that variable. So while X is less than 10 Print X is going to break
because of the fact that X is not to find. So you have to do a little bit more legwork with your wild loot
and predefined whatever your variables going to be.
In this case, we're gonna say X equals zero. While X is less than 10
plus equals one. This is the same thing as saying. X equals X
plus One is just a shorthand to helpyou increment with a little with a very little bit less
so while X is less than 10 print x, an increment,
and sure enough, you can see we print 01 through 12345678 and nine. Now I want you to have a look and really notice that implementation piece right there.
Because if we didn't have that code, if we just had
people zero while X is less than 10
If we run this code right now,
it's never going to stop printing zero, because again, the wild loop requires you to do a little bit more of your own work.
It doesn't really know how
how to change that variable automatically or how to interpret it.
So we've got our wildlife.
But what if we wanted to
reach a specific piece of information? For example, what if we wanted to do something like
taking a list apart piece by piece? There's a useful function we gonna use here, which is, uh, that lists name dot pop,
but that does is it removes the last item from the list and prince to your screen, and again we'll talk more about functions and methods in a later video for now, we're just gonna make use of that.
It's a four not for other gonna do. Wow,
is greater than zero. Len is another function That's just gonna tell you how many items are in your list
while the length of l wanna straight injera. While there are more than zero items in the list
and you could see here there's gonna print 54321
But what if we didn't
have that evaluated quite the way we might want to What if instead, we had our infinite loop
Sorry. A little bit of dead areas. I'm building this out. Programming on screen is always an exciting endeavor because you never know when you're gonna mess something up
while X is less than one,
for example, I just messed that up by not rebuilding my list.
While X is less than one
Now this is a potentially infinite loop here because we're never modifying X and again you'll see this happen pretty often in code where there's some. There's some tight, infinite wild loop that spins very quickly, and it's just designed to keep the program running while it waits for some kind of input.
But what we can do here is we can say l one pop,
and then we can have an internal if statement and internal condition.
zero remember, double equals is to check the condition rather than a sign it.
Make sure got yet right now, right Level of indentation.
And I remember breaks from our last video. Tell the Lieut Tell the loop. Hey, we're done. We feared out the piece we need. We've executed the code that we want to execute whatever break the loop.
And so instead of throwing up in error or having some sort of infinite loop, it says, Okay, we've popped all the items out of that list. We're done. We can leave.
That's really all there is to using while loops in python again. They're implemented very similarly to four loops. Uh, except for the fact you have to do a little bit more legwork with them. I hope you enjoyed this. Listen, I hope you find valuable as with EF four ended. Basically everything else in module to you can get some extra practice over our supplemental materials. You can also
work a little bit in our lab,
the wonderful love right by the spectacular company. Next tech.
And you can jump into that work with the four loops for work with the violence for a little bit and then come back because lesson for we're going to learn more about logical escapes and python. As always, I am your instructor, Joe Perry. And I just want to thank you again for watching intruder Python here on Cyber eri on demand.