3.1 If-Statements in Java
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
Already have an account? Sign In »
Hi and welcome back to the course. I hope you guys are doing well. And if you remember in the last video we wrapped up module to and in this video lecture we're gonna be starting module three, which is all about control. Flow and structures
Now is always I've listed out some learning objectives for you so that you're clear going into the video lecture on what you should be expecting to learn out of this lesson.
So first off, we're going to be understanding What if statements are?
I also understand why or when we would ever have to use them. Why do they even exist in the first place?
As well as understand this syntax of if statements. If you have forgotten what syntax means, it essentially refers to the grammar or the rules in which you can write a certain thing. In this case, we're talking about if statements
All right, So what is controlled flow?
Now if you just piece apart the word itself, control and flow isn't that complicated to understand when we talk about its general context. But when it comes to programming, control, flow is essentially how your program makes decisions and not only decisions but decisions about certain parts,
and the regular order in which code is executed is basically from top to bottom. So any program that you write code executes from top to bottom. But as soon as you add in some control structures such as four loops If statements a break, statements continue statements, return statements,
all of these
separate control structures or statements altered that control flow. Now, instead of going from top to bottom, your program goes down different pathways.
All right, so here is a diagram of me demonstrating what control full is. So you essentially have a condition. And once you start, you check. If that condition is true, if it happens to be true than a certain statement is executed, and if it is false,
then something else is executed. And this is a very basic,
high level example of what control flow is
all right. Perfect. So not moving onto if statements, what are if statements to begin with
and if statement is a programming conditional that have proved true, performs a function or displays information,
and here is an example of an actual if statement now we carefully analyze this program or look at it, we can see that it is asking a user to enter a number, and it is doing that through a scandal scanner. Sorry, and that is through the Java that utility scanner
package that we have imported.
Then once the user enters a number, that number is stored into the user number variable
Moving on. This is a mean part that is related to today's lecture. We check if the user's number equals five using an if statement,
and if it does equal to five, then we simply print out to the consul. You entered the right number.
Otherwise, that is what this else if is doing so each if statement can come within else. If and you can write that it is an an optional thing, but you do not have to do that. So I'm saying, if the number is five, then print out you entered the right number. Otherwise,
if it is not five,
then print out. Sorry you entered the wrong number. So this is a very basic example of how an if statement work
some other examples of if statements could be, Let's say we're trying to calculate some sort of cost to any event. Or let's say we're trying to calculate if someone qualifies to register for a class or something like that. We have to check if a certain condition isn't met
and it just gives it away, right in the word where we say, if
that if is what will be what we're going to be using in our programs, which will help us make decisions all along the way.
All right. So I hope you understood if statements and what we went over in this video lecture and just to summarize everything we discussed. What if statements are
as well as I went to use if statements, which, as I mentioned, is when you need to make certain decisions
as well as why we would need them?
And then we discussed how we can actually write them. It's a simple as writing if and then else if if you have a need of going a different path in your program,
all right, Perfect. So now in the next video or in the next of the electorate, we're gonna be doing a lab, and in that lab we're gonna be making a fare ticket calculator, which will calculate um, an individual's ticket based on their age.
So thank you very much for watching. And as always, if you have any questions at all, please do. Let me know when you can contact me through lengthen. And I'd be more than happy to answer any questions. I look forward to seeing you next video and have a good day.
3.2 Fare Calculator Part 1
3.3 Fare Calculator Part 2
3.4 For Loops in Java
3.5 Count Program
3.6 The Switch Statement