Hello and welcome back. It is in front of Python here on Cyber Eri on demand with your instructor, Joe Perry. And this is gonna be lesson five where we're gonna talk about the program Basics of wild loops.
So in the last lesson, we discussed four loops. You discuss the concept of looping, of implementing a piece of logic that's going to be used over and over again. In this lesson, we're going to take that same general concept we're going to use it to understand. While loops were gonna also understand the relationship between wild loops if statements and four looks so remember from the last lesson that wild loops or that four looks rather
repeat, given sequence until the condition is met
wild loops do the exact same thing.
The distinction that really is is most important is that what while loops do is that they just evaluate some ongoing phenomenon, some ongoing condition. It can be used the same ways for love, but often it's used for other purposes.
An example here is while it is dark outside Tim to the computer screen read of you. If that's confusing to you, there are a lot of applications that do that because it's better for your eyesight. And if you're someone like me who spends all day staring at a computer screen, you're gonna take every little bit you can get.
But the idea here, like I said, is that while looks are used to implement
against an ongoing phenomenon, ongoing condition so often times when you write a program that's intended to have user input, for example, you know the Internet or, for example, an Internet browser rather not the Internet or a word processor, really, most of the application to use day today.
Generally speaking, somewhere inside of those applications there is what we call the core loop, which is just a simple wild loop
that is waiting for signals and processing those signals based on your input.
A single handling can get kind of complex. We're not gonna talk about that. Actually, it all in this particular class that's gonna come up during intermediate and advanced python, however, and we'll talk about it pretty extensively, then.
The point that I'm making here is that while loops are often used for infinite loops or used for loops that are intended to last for a very long time.
So while X is less than 10 print and then increment X, now you can see that this does the same thing that a four loop would have done. But the difference here one is that we're implementing the increment ourselves. That's not happening in the wild loop. It's not happening
in the internal logic of Python. The other thing that's important to note here is that instead of using four where we're going to evaluate for each item, what's actually happening here is just that were repeatedly evaluating the The X is less than 10
and it doesn't necessarily change. Like I said, you have an infinite wild loop, and it's entirely possible to construct a wild loop where you just don't increment the actor. You don't increment whatever value, or you don't change whatever signal, and therefore the wild just keeps execute.
So while X is less than 10 we're going to print it, and we're going to increment.
So, of course, we're going to set X equal to zero the beginning. This is a case with wild loops, where you will have to usually assign an initial value for loops. Python can often do that for you based on the information while looked, you usually have to do it yourself.
So X is less than 10. That is a true statement.
We're going to print it. We're going to increment. And then we're just going to repeat those steps, looping exactly the same way we did with four loops
changing the information,
forming logic and then evaluate
until finally X equals 10 which in this case, we were only looking for while X is less than 10
and we're going to say that it's false, obviously, 10 equals. Tended is not left then.
And so we're going to end our execution. We're going to give back control to whatever code comes next. Whatever part of Python code or whatever part of your module is happening next.
Another example here that kind of demonstrates a difference. X equals the letter a while, and this is totally pseudo code. This wouldn't work in Python the way it's written. But while X is not equal to see the exclamation mark, Equal sign is a
It's a simple thing.
I lost the word. It is a symbol in python, which means not equal to the logical inversion of equal to. So while X is not equal to Z,
X equals the next letter. Then outside of this wild loop, as its own instructions say, print acts, you could see that I say here these air separate instructions, which executes sequentially.
Which means that this wild loop is going performance behavior before the print statement ever happens. So it's going to look at the letter and say a note that's not see So we're just going to cycle through a B C D E f g all the way it out until finally gets dizzy and it is up.
Found it while Luke has done. And then it feeds to the next line of code, which in this case is going to be printing that that letter. So in a while, Luke implemented like this on Lee, the letter Z will ever actually print the wild. Luke will execute its behavior completely and then give control back.
So another check for you a sample while Luke
and is going to be given the initial value of 100
and while and is greater than 10. You'll print and the deck Ament.
I'm gonna go ahead and give you just a few seconds to see. Actually, the question here, how many numbers will be printed? So I'm gonna give you just a few seconds. Positive video. Have a look. See if you can figure out how many numbers going to be printed.
All right, let's go over it.
The answer is 90. The numbers 11 through 100 backward. So it's gonna be 199 98 97 96 all the way down, it will print 11. It will then say n equals 10. Which, of course, is not greater than 10. We're done executing. Move on.
So that's all there is a lesson five, which is wild loops. I am glad you've made it this far with us. If you have stuck with us all the way from the course introduction in less than zero, I have excellent news for you, Which is that from here on out, we're gonna spend a very, very little time in our power point. Almost all of our time from now on is gonna be spent in Are you bun to 64 bit bm
starting with less than six. Which is the next lesson Python basic
and we're gonna talk all about how you can create a script you're gonna get right your first program. And we're going to start spending all of our time in that Viet
From here on out, the slides are pretty much gonna be used to set our objectives and perform are summaries and our reviews. So thank you all for sticking with us. Hopefully you've learned something so far. Hopefully you're excited to start coding. I'm very excited to start going with you. I look forward to having you all back in our next video. As always. I'm your instructor, Joe Perry. And thank you for watching this on Cyber eri on demand.