Welcome back.
In this video I want to cover the equality operator because it's really important for you to understand
how that works.
So let's say we have two numbers.
So int num one and we have int num two.
And now we want to see if they are equal.
So if two different numbers or two different things are equal in the sense of what content they contain.
So let's say in this case it would be equal because num one is zero and num2 is also zero.
So how do we check that we can do the following.
We can have a boolean.
So bool is equal.
And then we just compare num one to num two.
And we can just use this double equal sign.
So what this will do is it will check those two numbers and see if they are the same.
And if they are the same then is equal is going to be true.
And if they aren't the same is equal is going to be false.
Okay.
So there is this other very pants where it is not equal, where you see you're using this exclamation
mark and then the equal sign.
So what this will do is it will check whether those two aren't equal in the sense of they don't have
the same content, the same value, so to speak.
So this here is going to be true.
And this one is not going to be true because num1 and num2 are zero.
So this one will be true because zero is equal zero.
And this one will be false because zero is not equal zero.
But it's trying to see whether they are not equal.
So if they're not equal that means that this statement will be true.
But if they are equal that means the statement will be false.
So you see, this exclamation mark is really a negator.
It's saying negate equal.
So is it not equal.
So let's say you were to check if two numbers are equal.
What you can do is you can say, let's say num one is equal equal.
And then now let's go a little more wild here read line.
And then we're converting whatever the user entered into an int.
So int dot parse.
And we're parsing whatever the user has entered.
And if the number that the user has entered is the same as what the PC has entered so to speak, so
as whatever this num one is, then we're going to say numbers are equal.
So CW numbers are equal.
Something like you guessed the number, right.
You can make a little game out of it.
And I would recommend you try this little game itself yourself as well.
So in this context I'm going to show you something neat.
And that is how to comment the rest of your code out.
So I'm going to say I want to, uh, comment everything out up to this point.
So how did I do that?
Well, the magical trick is to use this multi-line comment.
So you use a slash and then a star, and then this is the start of your comment.
So you see all the code is green which means that everything is commented out.
So it's not being considered by the compiler when when compiling the code.
And then here you see this is where it ends.
So everything after that is not part of the comment anymore.
So this console read key will still be executed.
So I'm just commenting that out for now.
And I'm going to have an else block here as well where I'm going to say numbers aren't equal, aren't
equal.
And maybe we tell us as well that we want a number.
So we're going to say CW, please enter a whole number and let me run that to show you how that works.
So here please enter a number and I'm going to enter five.
And it says numbers aren't equal okay.
Let me run this again.
This time I'm going to enter zero.
And it says numbers are equal.
So that's what this double equal sign can do for you okay.
It checks whether the thing on the left hand side and the thing on the right hand side are the same.
So you have to be really careful with the equal signs because this can very quickly lead to errors.
I've had these errors in the past where you forget to use a double equal sign okay.
So in this case it doesn't matter.
It doesn't complain.
But usually if you forget it, it could very well happen that the compiler might not see it.
So one equal sign is for assigning a value.
So here we're saying zero is going to be assigned into this variable called num one.
The double equal sign however, is comparing what's on the left with what's on the right.
And if they are the same then this statement will be true.
So true will be stored inside of this boolean.
Okay.
So that's basically the difference between the two.
And then we also saw the not equal.
And that was basically.
This little exclamation mark equal sign.
Okay, so that's it for this video.
See you in the next one.