0:00 What's Up Guys? This is bucky. welcome to your eighth c plus plus tutorial and in this tutorial, 0:04 i wanna talk to you guys about something called if statement. now the if statement 0:08 is a way we can have our program make very 0:11 basic decisions. What we are going to be doing is 0:15 we're going to be giving our computer program a test. 0:18 and its gonna run that test. If the test is true, 0:21 then it is gonna run a certain bit of code. If the test is false, 0:25 it's not going to run any bit of code. So, depending on that test, depends 0:29 whether we run code or not. 0:30 So it sounds confusing, but it's actually incredibly simple. 0:34 so let me go ahead and I'll show you the syntax for an if statement right now. 0:38 the syntax to make an if statement as 'I' 'F'. 0:41 You just go ahead and take the word 'if' and then go ahead and add parentheses. 0:46 now inside our parentheses is where we're going to be making our test 0:49 now after those parentheses, go ahead and add curly braces 0:53 now this is called the body of the if statement. and now here is where we write the 0:58 code 0:58 to run if the test is true. so let's go ahead and make a simple bit of code. 1:03 Let's go ahead and write like cout, uhm, 1:06 Bucky is AWESOME 1:10 so it for test is true it's going to print out Bucky is AWESOME on the screen. 1:14 If the test is false it's not going to print out anything. so let's go ahead 1:18 and let me talk to guys about 1:20 different types of tests. The first test I want to show you guys 1:24 is the greater than test. and this simply tests if 1:27 one value is greater than another value. so if 1:30 5 is greater than 3, go ahead 1:34 and run this code. so 5 is indeed greater than three. 1:38 so this is true. so whenever we build and run this it's gonna say 1:41 "Bucky is AWESOME. pretty cool huh? So now it's go ahead 1:46" and make something like, uhm, is one 1:49 greater than 3? So, it's going to test this. is one greater in three? 1:53 well this is actually false. one is less than three, so it's not gonna run this 1:57 bit of code. 1:58 so go ahead build and run this. and as you can see, it did not print out "Bucky is 2:03 AWESOME" on the screen. 2:04 how sad. so of course we have the greater than test 2:08 we obviously have the less than test. 1 less 2:11 than 3. Well, now this is going to be true so it's going to print out "Bucky is 2:15 AWESOME" on the screen 2:16 so, let's go ahead and run this. and indeed it prints out "Bucky 2:19 is AWESOME". so aside from greater than 2:22 and less than, we also have these two tests. 2:26 greater than or equals to, so 2:30 whenever we tested whether 3 is greater than three, 2:33 this test is gonna be false because three is not greater than three 2:37 three is actually equal to three. well if we want to test if 2:41 3 is greater than or equal to 3, we use greater than 2:45 with the equal sign after it so now whenever we run it. 2:48 is 3 greater than or equal to 3? Yes. 2:51 3 is equal to 3 so print it printed out "Bucky is AWESOME" 2:55 so aside from that we also have the less than or equal to. 2:58 so if you know is 1 less than or equal to 3 3:02 yes one is less than or equal to 3, so it is going to print out "Bucky is awesome" 3:06 so again what I want to show you guys is that you have 3:10 greater than, less than, greater than or equal to, 3:13 and less than or equals to. So now those are called the relational 3:18 operators. we also have two more tests that we can do 3:22 and these are called a equality operators. this 3:25 is a really simple test. It tests whether one value is equal to 3:28 another value or if one value is not equal to another value. 3:32 so in order to do this go ahead and write is 3 3:36 equal to equal to 3? and you might be thinking all right, 3:41 why don't I just use one equal sign? why didn't they make it that way? 3:44 well whenever we were creating variables such as int 3:48 X equals 8. the one equal sign the single equal sign is a sign for creating 3:53 variables in assigning values. 3:55 so that's why they decided that two equal signs was sufficient for testing. So, 4:00 remember 4:00 uhm, a common mistake is to put one equal sign in their 4:04 and you're going to get an error, or something terrible is going to happen. so whenever 4:07 you're testing 4:08 you need two equal signs. so let's go ahead and run this test. 4:11 is three equal to three? well yes. it is, so it's going to print out 4:15 Bucky is AWESOME. Uhm, give it another test like is seven 4:19 equal to three? well no it's not. so it's not going to print out Bucky is AWESOME. 4:24 so that is one test is called the "equals sign" "equals sign" 4:27 or equal to test. And, 4:30 there's one more test I wanna go over and thats explanation point equal sign. 4:35 and this is the key word for not equals to. so 4:38 is 8 not equal to or in other words is 4:41 eight different than eight? Well no, it's the same 4:44 so it's not going to print out everything. is 4:48 10 different than 8? well yes, it is. So, that's going to be true 4:51 it's gonna print out Bucky is AWESOME. So, that is all the tests that I have for you guys. 4:56 4:56 and that's all the tests C plus plus. again to recap one last time 5:00 greater than, less than, greater than or equal to, 5:05 less than or equal to, equal and not equal. 5:09 so now that we know all those tests, uhm, 5:12 I probably should tell you guys this, people typically don't 5:16 and by people I mean computer programmers computer programmers typically don't 5:20 just test two numbers against each other. They usually 5:23 have variables that they usually test against each other. Like int a 5:26 equals 98. int b equals 76. 5:31 and then they test something like, is a 5:34 uhm, greater than b? we'll go ahead and run this 5:38 98 is indeed greater than 76, so 5:43 of course that is true. It is going to print out Bucky is awesome. an aside from that, 5:47 uhm, you either have two variables to test or you have a variable 5:51 and a value, like is 98 greater than 5? 5:54 something like that. we can actually mix variables with values. 5:58 and that would be true as well. so again you can either have to values in here, 6:02 two variables, or variable on one side and a value on another side. 6:07 pretty cool, huh? so that's the basics of, 6:10 uhm, again relational operators are the greater than and less than one, 6:14 and the equality operators are the equals equals, and 6:17 explanation point equals, so now that we know 6:21 had make a basic if statement. again to recap on last time. 6:24 if your test and then the body 6:28 and its gonna run the test in a that code is true is gonna run the body 6:31 that's the basics of "if" statement. Now that we understand that, we can begin 6:36 enhancing our programs a little bit more. so in our next tutorial what I am going to be doing 6:41 is I'm going to be having the user enter two numbers, 6:45 and we're going to be comparing those numbers and depending on what numbers 6:49 they answered 6:50 run a certain bit of code. So now as you can see 6:53 we are just building and building to our knowledge a C plus plus to make better and 6:57 better programs. 6:58 so don't skip over if statements, because it's a huge part a C plus plus. 7:03 so for now that's all I have for you guys. so thank you guys for watching. In the next tutorial, 7:07 we're going to be building that calculator thingy, so it's gonna be 7:10 awesome so thank you guys for watching and don't forget to subscribe. And don't forget to check out my website