 Welcome back everyone. Today we're going to talk about if statements in go. So in prior videos we talked about loops and we showed a for loop and we've already talked about setting variables. Today we're going to talk about if statements and we're going to again be using some variables. So I've already set two integer variables here. Integers are numbers, non-decimal numbers, and then I have two string variables. So here I have int1 equals zero, int2 equals one, string1 equals the word string, string2 equals also the word string. Now an if statement is really useful for checking whether something is true or false. So it's really common to check between two variables to see how they compare to each other. They could be the same, they could be in this case less than, it could be greater than. So we compare two variables to see whether the check is true or not, true or false, and if it's true then we run whatever code is in between the brackets here. So we have our if statement and then we have our check, what we're checking, the check condition, and then we have the bracket and then we have everything inside the bracket is what is ran if that is true. So let's go through and look at this real quick. We have this if statement. So if int1 and int1 is currently equal to zero is less than or equal to, this check here is less than or equal to int2. Well int2's value is one, so if zero is less than or equal to one, that is true because right now int1 is less than int2. So since that's true, we're going to run everything inside this bracket. So we would, we would run format print line and then int1 is less than int2. That's what would print out. Now since this first if statement, this first check is true, we would not check anything else in the rest of this block. So this if statement is all one block of code, but since the first p, so the first check that we have is true, we do not go through and check everything else. So for example, here I have an if statement comparing int1 and int2. And if that's false, then I would go to another if statement and check string1 and string2. If those are equal, then print out string1 is the same as string2. If that is false, then print out that none of them are true. Both the ints was not true and the strings were not true, so none of them were true. Okay, so we have if and else. So if I run that, we have int1 is less than int2. So in this case, our first check was true. So we printed out int1 is less than int2. And then we stopped. We didn't go on to any of the other checks. So now let me put this int1 value to two. So what's going to happen is int1 less than or equal to int2, that's going to be false, which means that this block will be false. And we will move down to the else if check. Okay, so what do you expect will happen while string1 and string2 are currently the same thing, they're equal to the same value. So we should print out string1 is the same as string2. So let's run that again. And string1 is the same as string2. Okay, now what if I add anything to either one of the strings. Now they're not equal. So what we expect to happen, the first check is false. So we do the second check, the second check is false. So we go down to the third check. And the third check is just if none of these were true, do this. Okay, so then what will happen is none are true. Because it was our first check, if int1 is less than int2, false. If string1 is equal to string2, false. So then if none of the others were true, then type none are true. Okay. So that's how we do an if statement. And this is actually an if and then else if else if is relatively common, whenever you want to check something in a particular order. So for example, int1 and int2 are not related to string1 and string2 at all. But maybe for some reason I want to check if this is not true, then do this check as well. Okay, so put these together whenever you want some sort of logical flow between checks. Now what I could do is just put if string1 is equal to equal string2. So let's copy this. And I'll just call this string1 to string2 check. So this is a different if statement. Notice this block of code is separated from this block of code. You can tell by the brackets. So the brackets for this block actually end here. And then I have another if statement. So these are completely separate. First, this entire block will run. We'll get some sort of result out of that. And then the second block will run. So let's go back to our original state. So int1 is zero. So what will happen here is this is true. So what we should print is int1 is less than int2. And then we're done with that block. So we will move down to if string1 equals string2, which it does now. Then we should print string1 string2 check. So we'll get two print statements here with two different blocks. Int1 is less than int2 because this first check was true. And string1 and string2 check because the second block ran and it was also true. So you can put the if statements together if you want to do checks related to each other. Or they can be completely separate if you want them to run one after another. Now, so far we've used equals. And for integers we've used less than or equal to. We could just as easily say less than, but I put less than or equal to. For checking whether strings are the same, we use these double equals sign or an exclamation point. So double equal sign means equal exclamation point equal sign is not equal, not equal. Okay. So here we have, I'll move this to two again. So now we have our strings are the same. And then I have a check where they're equal and I have a check where they're not equal. So we know that either this will print or this will print because they're testing basically for exactly the opposite thing. Which one do you think it is? I think it's going to be string1 is the same as string2. Okay. Let's try that. String1 is the same as string2 because string1 equals equals string2. So they are the same string. String1 is not equal to string2. So that's not true because they're not different. Okay. Now, if we do something like string exclamation point in the string, if we run that again, then we get none are true and string1 string2 check. Why do we get none are true? Because first off int1 is greater than int2. So that's false. So then we move down to the second one string1 equals equals string2. Are they the same? No, they're not. So that's false. So then we get this else statement and none are true because that's the last thing we do if all the checks failed. Okay. Then we go to our next block of code. If string1 is not equal to string2, then print out string1 string2 check. Well, that's true because these are different strings. Okay. Even though they contain the same text, this one contains an extra character, an extra letter. Okay. So that's fine if you want to run simple checks of logic, whether something is the same or less than or equal to or not the same. But sometimes we want to check multiple things at the same time. So for example, maybe I wanted to know whether int1 is less than int2 and string1 equals string2. So I have two checks that I want to do. I can either write that as two if statements or I can combine them all into one if statement. So we can do if int1, I'll just do greater than since our variables are already there, int2. And then instead of just putting my bracket, I can just put and and string1 is not equal to string2. Okay. Now I can put my bracket and say, what are we going to say here? Double test, double test. Okay. So how we read this is if int1 is greater than int2 and string1 is not equal to string2, then print out double test. Okay. So we should see that. And here we have our double test at the bottom. So none are true because both of these were false. We have string1 string2 check because that was checking by itself. And we have double test because int1 is greater than int2 and string1 is not equal to string2. What happens if I just change this? So here we have int1 is greater than int2. That's true. And string1 equals string2. That's false now. But we're using an and statement. So do you expect double test to actually print out? No. Double test doesn't print out because for an and check, both of these have to be true. Okay. But right now one of them is false, one of them is true. If we want only one of them to be true, so either int, the int check could be true or string1 equal string2 could be true. And instead of and, we use or. And that's a double pipe. Okay. Double pipe. So let's run that again. And then we should see double test. So here we have our or statement. int1 is greater than int2 or string1 is equal to string2. Right now this is false and this is true. So as long as one of them are true, then we will print or we will do whatever is inside the brackets. Okay. So this is getting started with if statements. Really powerful. This is kind of where everything happens because you want to check the current state of something going on and react based on how that state is set up. So the if statements are kind of the basic form that you'll need in almost every programming language. And most programming languages look similar to this. A little bit different. They basically all have if statements. Most, I think, yeah, most have else if and then if there's an if they always have an else. So you'll usually see if and else. Sometimes you'll see else if. Sometimes we check just one variable. Sometimes we check the state of multiple variables against each other, either with and or or. And then there's some other ones. But just with these checks that I've shown you here, you can do most of your programming actually. Okay. So that's it for if statements. Thank you very much. Thanks for watching. If this was helpful, please like and subscribe. Also, please consider supporting us on Patreon. Your support lets us focus on making better tutorials for everyone.