‫In this video we're going to look at comparison operators and logical operators.
‫And you can see that I've put some comments in here.
‫So we can see each operator as well as what it does.
‫And I'm just going to go through and give you an example of each one.
‫So let's start off by creating a couple variables.
‫I'm going to set x equal to ten.
‫And then I'm going to set y equal to a string of ten okay.
‫So the first one is equal to which is to equal signs.
‫And instead of putting it in an if statement I'm just going to do a var dump to see what we get.
‫If we say is x equal to y equal to y.
‫And if I reload this we get true.
‫Now even though this is an int, this is an integer.
‫This is a string.
‫We get true because the double equal sign only tests the value.
‫It doesn't test the type.
‫If you want to test the type, then you can use the identical to operator, which is a triple equal
‫sign.
‫So let's comment that out.
‫And then here let's add another equal sign.
‫And now we're going to get false because they're of different types.
‫If I were to change this to an integer and then reload, then we get true because it matches not only
‫the value but also the type.
‫But I'm going to put that back to a string.
‫Now we have the opposite which is not equal to, which is the exclamation equals.
‫So if we do that let's say not equal to reload and we get false, we get false because these are equal
‫okay.
‫Remember this is this is comparable to the double equal sign.
‫So it's not looking at the type.
‫So they are actually equal.
‫If I change this to an 11 and reload then we get true because then they're not equal.
‫And that makes this true.
‫All right.
‫And then at the same time we have not identical to.
‫So if we do that so now we get true because these two are not identical.
‫If we once again make this an integer then we get false because now they are identical.
‫So this evaluates to false.
‫All right.
‫Next we have.
‫Oh, and we also have this way of doing not equal.
‫So basically we'll copy that down.
‫So this is the same.
‫This right here this this exclamation equal is the same as if we were to do that.
‫So that's going to give us false because these are equal.
‫Okay, then of course we have less than and greater than.
‫So let's do that.
‫So if x is greater than y.
‫And of course we're going to get false because ten is not greater than ten it's equal.
‫And we can also do less.
‫So less than.
‫If we do that, we also get false.
‫And then of course we can do less than or equal to.
‫That will give us true because ten is less than or equal to ten.
‫Same with greater than or equal to.
‫So if we do that we should also get true.
‫So those are the main comparison operators that you'll use.
‫Now we also have logical operators that you can use when you want to test more than one thing.
‫So let's create two new variables I'm going to set a equal to let's say ten.
‫And I'll set B equal to 20.
‫And then I'm going to do a vardump here.
‫And the first one or the first two I want to look at are.
‫And so you can both of these are the same.
‫You're more commonly going to see this the double ampersand over and being spelled out.
‫But this will return true if both are true or and it could be two.
‫It could be three.
‫As many conditions that you want to check.
‫So let's say a is equal to ten.
‫And let's say B is equal to 20.
‫So if I reload, we get true.
‫Oops.
‫Let me comment this out up here.
‫So we get true because both are true right?
‫A is ten.
‫B is 20.
‫If I change one of these if I change that to 11 then we get false because they're not both true.
‫And then you can also do it this way with instead of double ampersand, we can say and and that will
‫do the same thing.
‫All right.
‫And at the same time we also have or.
‫So let's comment these out.
‫So or can be represented in two ways.
‫We can do the double pipe which is the more common.
‫And then we can also just spell out or and if I go ahead and run that we're going to get true because
‫at least one of these is true.
‫They're actually both true.
‫Even if I were to change one of them, change A to 11, it's still true because it's one or the other.
‫If I change B to 21, then they're both false.
‫So of course we're going to get false.
‫So that's or now we also have exclusive or which isn't used as much.
‫I don't really use that much at all, but this will be true if only one is true.
‫Okay, if more than one is true, it's going to be false.
‫If none is true, it's going to be false.
‫So let's see what happens if we do exclusive or so it's x or.
‫And right now a is equal to ten and b is equal to 20.
‫However we get false because more than one is true.
‫If I change A to 11, then only one of these is true.
‫So we get true.
‫If I change B to 21, then none of them are true.
‫So we get false.
‫So that's exclusive or.
‫And then we have the exclamation which just means not true.
‫So whenever you see the exclamation before something it just means not.
‫So let's do a var dump.
‫Of, let's say not.
‫And then in parentheses I'm just going to say a.
‫A is equal to five.
‫If I reload that, I'm going to get true because A is not equal to five.
‫So that gives me true.
‫If I do set A to five and I say not.
‫Then I'm going to get false because a is equal to five.
‫All right.
‫So those are the basic comparison and logical operators.
‫In the next video I want to get into using conditionals using if statements in loops.