 Hey everybody, this is Brian and if you're following along this is the sixth video in our visual basic tutorial today We'll be talking about the if statement First off. What is a statement? The statement is pretty much anything. I know that's not the technical term I'm gonna get hate mail for it, but That's a statement. That's a statement. That's a statement. You've seen some statements several times before What we're talking about is the if statement. This is how you put logic into your program in other words This is how you make it do stuff It's very simple if Then it's the syntax Let me move the mouse you can see it literally reads like a story if Bob Dot happy equals true then Bob smiles So today we're going to just use a car analogy and we've learned about variables and we've learned about boleens Oops started so just write dim started as boleen this will represent whether or not the car is started And we'll just set it to false Remember a boleen is like a light switch. It's simply on off true or false Then we're going to say if whoops dyslexia much started equal true then You notice how it automatically puts in the end if the if statement Must end at some point. This is called a code block anything in here is within the code block of the if statement You can also have a single line of statements, which we'll cover in a minute, but I want to explain what this does console Dot and we'll just say right line Car whoops is started Having typing difficulties today apparently So if started equals true then right car started otherwise car is stopped Or let's say off cars off Now when we run this because the started value, I'm sorry started variable is set to false Which one of these do you think we'll run? Let's find out car is off So as you can see that is how you make decisions Now you can combine these two statements By saying else if car started equal true then else do this This is an entire code block right here. This is treatment it treated as one statement Let's run this see what happens the car is off So you get the same results, but it's cleaner code It's easier to follow along it reads like a story if the car is started then do something You know otherwise or in this case else do something else So now we're going to set the car to start it just to show you what happens And it says car started So that's the if statement I Realize if you're new to programming this might be a little mind-boggling So let's just peel the cover off this and explain plain English what this is doing You have a variable and the if statement says if a variable is a certain value then execute this code else Execute that code one more time if the variable is a certain value then Execute this code else Execute this code and remember you have to end in an end if unless you're a single-lined if statement Notice how it automatically puts that we can also say a single-line if statement We'll say the car is really started notice how suddenly the end if is it says End if must be preceded by matching if what it does is in memory It creates an invisible in the F right here. So you don't need this and if anymore you can just delete that So you can take that whole statement right here and sum it into one line That's typically bad form Don't do that unless you really have a reason to I know some programmers love doing that But it really like makes life miserable for people reading your code As you can see cars started cars really started. So it's executing both these if statements So that is the if statement it's actually pretty simple You notice that in this one we did not do equal true. Why is that? The if statement is always translated in memory to a boolean and on or off. It's true or it's false so How would you say? If it's not started. Well, you could say started equals false That's the easiest way There are other ways, but I don't want to confuse you at this point Just know that the if statement basically translates whatever value you're comparing Into a boolean in memory Okay, let's move right along here to show you what I'm talking about. Let's just erase all our work here and do oops Name as string Equal and then just enter your name if name Equals Hello Let's throw an else in here real quick console right line Now what we're doing is we're saying name Is equal to Brian and then we're saying if name dot equals hello Then and what these equal function does is it takes the parameter and compares it to the current variable in this case Brian so you can clearly see that name does not equal hello it equals Brian therefore it's going to say does not match Run your code Does not match now you can say if name equal Hello, and that does essentially the same thing, but the equal statement actually is treated a little different Microsoft actually recommends you say variable dot equals and the reason being I Give you a little lesson on computers here but the reason being is you're checking to see if the string hello exists and The equals actually compares that value to another value So in summary if you want to give me a good programmer drink the Kool-Aid do a Microsoft telling you to do because this is their product and Use the name dot equals But you can just as easily use the equal sign I know starting out a lot of people like to use the equal sign because it's much easier to read and there's no harm in doing that Just know that you can do it either way That's it for this tutorial. We're running out of time. I hope you found this educational and entertaining and Send me a message or just leave a comment. Thanks