Time
2 hours 57 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
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.
00:11
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
00:31
repeat, given sequence until the condition is met
00:34
wild loops do the exact same thing.
00:36
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.
00:48
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.
01:03
But the idea here, like I said, is that while looks are used to implement
01:07
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.
01:23
Generally speaking, somewhere inside of those applications there is what we call the core loop, which is just a simple wild loop
01:30
that is waiting for signals and processing those signals based on your input.
01:34
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.
01:45
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.
01:53
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
02:07
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
02:21
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.
02:35
So while X is less than 10 we're going to print it, and we're going to increment.
02:39
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.
02:53
So X is less than 10. That is a true statement.
02:55
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
03:02
changing the information,
03:05
forming logic and then evaluate
03:07
until finally X equals 10 which in this case, we were only looking for while X is less than 10
03:14
and we're going to say that it's false, obviously, 10 equals. Tended is not left then.
03:17
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.
03:27
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
03:40
It's a simple thing.
03:43
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,
03:52
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.
04:00
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.
04:15
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.
04:30
So another check for you a sample while Luke
04:33
and is going to be given the initial value of 100
04:36
and while and is greater than 10. You'll print and the deck Ament.
04:42
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.
04:57
All right, let's go over it.
04:59
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.
05:15
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
05:34
starting with less than six. Which is the next lesson Python basic
05:38
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
05:44
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.

Up Next

Intro to Python

This is an introductory course on Python for cyber security, giving students the ability to understand the basics of the language, solve problems with scripts and identify useful Python modules.

Instructed By

Instructor Profile Image
Joe Perry
Senior Technical Instructor at FireEye, Inc
Instructor