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 eri on demand I, as always in your instructor Joe Perry.
00:07
And in this lesson today, we're going to be learning about if statements that lesson three programming basics. So lesson three, our objectives are gonna be understand and define the term flow control understanding. Apply if statements and learn the components of if statements. Now this has a slightly python bent. The inclusion of the lift, which we'll talk about in a minute,
00:25
is something that Python uses that not all of the programming Lee, which is used
00:28
but this isn't going to be actual pipe on code yet. It's just going to be bent toward
00:32
so Flo Control. All flow control, actually is Is execution decisions made based upon some internal logic.
00:39
I want to say that again, and I'm gonna say it again. Throughout this course, it is an execution decision made based upon some internal logic
00:47
program. For example, my perform differ operations based on the keys you press. Almost all programs do award processors going to print the letter of the key you press or the symbol if you use shifted in front of capital
00:58
things like that.
00:59
That's a great example of flow control, because it's not something people generally think of as flow control, flow control, something that and it's it's a weird phrase to keep saying over and over again. But it's something that people often get kind of wrapped around the axle with. Get a little bit confused, don't really understand.
01:12
And really, it's because it's being overcomplicated.
01:17
The simple fact of the matter is that any decision your program makes based on some internal logic,
01:22
you know, some some evaluation of truth or falsehood
01:25
that's all flow control, that's all it is. And so don't you know, don't get too far into the weeds on it, just understand that it is a decision your program is making.
01:33
So if statement specifically in this lesson going back to the Boolean logic we talked about in our earlier lesson,
01:40
if is implied in all of those statements, right, all of those statements can be framed and generally are framed as if that
01:47
if aid was one and B equals one, then eh and vehicles one
01:51
or if a equals one or B equals one,
01:55
then A or B was one
01:57
It's really easy to understand. It's not really even understand. That's not a fair thing to say. It's more. It's very straightforward. It's all your doing with If is you're just using to evaluate a condition,
02:07
you'll often hear this referred to as a conditional and in the in the help sheets and help documentation that we provide.
02:13
It is referred to as a conditional state.
02:15
So some examples, if sort of from everyday life. If it is raining where a raincoat. If the subways late yell at the sign, that doesn't help. But if you've never lived in Washington, D. C. I don't know how to tell you how much better it makes you feel to shout at. A subway sign has done nothing wrong,
02:32
but it gets out a little bit of your aggression. And in D. C. That's very, very important.
02:37
If the Number X is divisible by three print yes to the screen. That's amore programmatic example. That's something that's going often show up in different in different
02:46
program, different tools
02:49
having menus that are based on a control number that is actually a number and in danger of some kind.
02:53
It's a very, very common paradigm used to control a program.
02:57
You'll see the graphic above me is a floater flow Church are a great way of trying, of learning to understand if statements, I'm aware that's probably pretty hard to read. That's OK. It's actually just an ex K seedy comic I mentioned before and I'll mention again. You're going to see a lot of those in this series and then basically everything I do because X K. C. D is glorious.
03:14
Um
03:15
so
03:15
e lift. The next statement is part of the if paradigm right we have. If 11 else Elif is a little bit less common like I mentioned, it's It's used in python. It's using some other languages, but not used in all of
03:28
the way he lived. Works is it is actually its own. If statement, it's sort of ah, hybrid of else. And it
03:34
if the first condition. So whatever you're If statement WAAS evaluates to false, then consider this condition and evaluated.
03:42
We're just to say that, for example, if
03:44
for the menu example I gave him a moment ago,
03:46
if the number is one
03:47
ad
03:49
states calculator, if the number is one, perform the ad operation.
03:52
If l. If the number is to perform this attract operation,
03:55
you lift the number is three so on and so forth. The idea here is just that Elif is an if statement that on Lee gets checked in the case that the proceeding, if statement was or the preceding the lift statement was false. Now you can have many, many E live statements in a row. There's not really a serious upper limit on it, though. Generally speaking, you're gonna want to avoid
04:15
too many of them just for code readability.
04:16
The final pair of the final part of this paradigm is the L statement. So else on Lee ever exists in the context of and if you live
04:25
else statement,
04:26
it exists also for a type of Luke, but we'll talk about that later. The point is, it only exists in the context of evaluation of truth or falsehood, determination, right of flow control.
04:35
If the previous valuation was false, then performed this operation. Now, unlike Elif, there is no new conditional being evaluated with else. It's simply if a
04:46
perform his behavior
04:47
else in all other cases, performing different behavior.
04:51
So that's that's really all there is to if you live in else. But we're gonna take a couple of examples here and make sure that we kind of understand it can break this down.
04:59
So here are the facts of the situation.
05:01
X is a number.
05:03
If that number is less than 10 you will print small
05:08
e lift. That number is greater than 100. You will print large else you will print medium.
05:14
We're gonna try it out with a view. Example x. In this first case, we're going to set equal to 999. Now, if that number is less than 10 if is going to the first day when we evaluate always in most programs within certain contexts,
05:28
your statements are going to be evaluated from top to bottom.
05:30
Functions will mess without a little bit, and we'll talk about why and how later. But generally speaking, you're going to evaluate from top to bottom. But even in cases where that might be messed up for some reason, you know you got complex go twos or whatever. If Elif and else will always be evaluated in the order of if the living else And if you don't have an if you can't have a Neil if Orrin Els. So if
05:48
that number is less than 10 print small Well, 999
05:51
course is larger than 10 so we're not going to print small that has evaluated to false. Therefore, we're going to consider the second statement
06:00
Hell, if that number is greater than 100. Print large. Well, the last time I checked, 999 is larger than 100. Therefore,
06:09
we print lurch.
06:11
Now what happens if X equals 15?
06:13
Well X. If that number is less than 10 we print small 15. It's still larger than 10
06:18
he lived. That number is greater than 100. Print large.
06:21
Well, it's smaller than 100 so we can't perform that operation either.
06:26
Else. Print medium.
06:27
Now again, there's no new evaluation, We're saying if it's some set of numbers, if it's within somewhere, simply if neither of the previous two conditions are met,
06:36
just print medium.
06:40
We have X equals one.
06:43
If the number is less than 10 print small. Of course, that's gonna be our first evaluation because that's the first line we check. And sure enough, it is small.
06:50
So that's all there is for less than three in this lesson. Again, we talked about the concept of flow control, which is which is an execution decision based upon some internal logic. Then we went ahead and we talked about if statements if you live in else and we understood the way that those three statements fit together and how they work,
07:08
join me in the next lesson, which is going to be discussing four loops that'll be less than four kind of worked out did not mean to do that, actually did not realize that that worked out that way until just now. I have been recording this course for two weeks, and I just realized the unintentional pump
07:21
anyway.
07:23
I'll see you back in less than 44 loops. As always. I'm your instructor, Joe Perry, and thank you for joining us 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