Time
2 hours 57 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
Hello, everyone. And welcome back to enter the python here on cyber. Very on demand.
00:04
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.
00:14
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,
00:21
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,
00:38
which I believe is less than three. Yes, listen, three fantastic.
00:41
When you record videos for 12 to 14 hours a day, it's released you to forget where you are.
00:45
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
00:54
wonderful, glorious pain. Anyway, back to the lesson Python three.
00:58
We open our interpreter here. Now you'll remember that if we do some if conditional,
01:03
and then coat
01:04
with four, we did four conditions
01:08
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
01:18
it's basically just evaluating some bullion value here.
01:22
No,
01:23
with four loops, you were able to do four
01:25
I in range 10
01:27
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
01:37
into that variable. So while X is less than 10 Print X is going to break
01:44
because of the fact that X is not to find. So you have to do a little bit more legwork with your wild loot
01:48
and predefined whatever your variables going to be.
01:51
In this case, we're gonna say X equals zero. While X is less than 10
01:55
prints,
01:56
backs
01:57
and then X
02:00
plus equals one. This is the same thing as saying. X equals X
02:04
plus One is just a shorthand to helpyou increment with a little with a very little bit less
02:08
so while X is less than 10 print x, an increment,
02:13
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.
02:23
Because if we didn't have that code, if we just had
02:27
people zero while X is less than 10
02:30
print axe.
02:32
If we run this code right now,
02:36
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.
02:42
It doesn't really know how
02:44
how to change that variable automatically or how to interpret it.
02:47
So we've got our wildlife.
02:51
But what if we wanted to
02:53
reach a specific piece of information? For example, what if we wanted to do something like
03:02
taking a list apart piece by piece? There's a useful function we gonna use here, which is, uh, that lists name dot pop,
03:08
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.
03:17
It's a four not for other gonna do. Wow,
03:21
Blend
03:22
No one
03:23
is greater than zero. Len is another function That's just gonna tell you how many items are in your list
03:29
while the length of l wanna straight injera. While there are more than zero items in the list
03:34
l one dot
03:38
and you could see here there's gonna print 54321
03:40
But what if we didn't
03:43
have that evaluated quite the way we might want to What if instead, we had our infinite loop
03:55
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
04:01
while X is less than one,
04:05
for example, I just messed that up by not rebuilding my list.
04:10
There we go.
04:13
While X is less than one
04:15
l one dot
04:18
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.
04:32
But what we can do here is we can say l one pop,
04:35
and then we can have an internal if statement and internal condition.
04:40
If Len
04:43
L one
04:45
zero remember, double equals is to check the condition rather than a sign it.
04:49
We break.
04:51
Make sure got yet right now, right Level of indentation.
04:56
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.
05:04
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.
05:13
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
05:30
work a little bit in our lab,
05:32
the wonderful love right by the spectacular company. Next tech.
05:36
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.

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