Welcome back.
And this week, we are going to look at another type of operators, the comparison operators, so comparison
operators are the ones that you can see here.
So double equal, not equal, less than greater than less than equal or greater equal.
So now let's see how they are used in.
First of all, let's create this variable called is equal.
And it's going to be the result of the following operation, which means five equal equal three.
So what does that do?
Well, it checks if the value on the left hand side is the same as the value on the right hand side.
So that's what this double equal sign does.
So it's comparing two values to each other and it's going to give us a boolean result.
So it says it's a boolean expression, even though we can simplify the boolean expression.
So let's just do that.
You can say it gives me the result directly, which is false.
But of course, that's not what I wanted, because what I wanted is to display this operation here,
which is just saying, OK, one side equal, equal the other side or is the one side the same value
as the other side of this equation here?
So if you do that, you will get a result, which is either false or true.
So if we do the same with five equals equals five, then of course the result will be true.
And in this case, it's super obvious because we can see those values.
But let's say they are hidden behind a variable where you can't always see the variable value, then
this will be a very useful operation because maybe you even want to do something based on that operation.
So let's say if this condition is true, then you want to run some code, then it's going to be very
important to do this type of comparison operations.
And of course, this is also something that we are going to look at later on, which are if statements.
But for now, this is our very simple operation that we have here.
So now let's go ahead and print something onto our console.
And I'm going to write is equal is plus is equal.
So what I'm doing here is I'm using concatenation.
So it's just.
Using this strength and then it's converting this into a string and just saying whatever the value is.
So if we run that we can see that is equal, is false.
So our is equal, is false.
So then, of course, our idee, which means our Android studio says, hey, you can convert concatenation
to a template.
So let's do that.
And you can see what it does.
It changes this to having a very different way of writing it.
So one was the concatenation, and this one is a template that we're using here, which requires this
dollar sign.
So what we can do is we can use this dollar sign and afterwards, whatever the value or the variable
that we want to use is, will be printed here.
So in this case, it's just going to be the result of whatever we had here.
So if we run, this will result in the same.
Type of print statement that we have here.
So I need to run it twice and we are is equal, is false.
So now let's use this a little more, because let's create a another comparison.
Where I'm just going to create is not equal is going to be five, not equal five.
So let's just test if that is true or false.
Of course, it's going to be false because five is equal.
Five.
But if we just print that now and let me put it this again, but now with is not equal.
All right.
So now I'm using is not equal instead of is equal.
And I'm going to comment this line out and I'm going to change the name here as well.
So it's going to be is not equal is.
And then let's see if it's true or false.
And we can see this is not equal, is false because five is equal.
Five, but we are checking if five is not equal five.
So this exclamation mark here says that it should be not equal.
So this year is another way of testing a comparison.
But of course, there are a bunch more that we have here.
So what we can check is, let's say the following.
So instead of creating a new variable for every single one of those comparison operators, let's just
do it in the print line statement directly.
So.
Is greater, so this case is five greater three is going to be and now I'm using something very cool
here because I'm using another pretty cool feature here of Kotlin, where we have the same principle
that we had here.
But now because we don't just have one variable that we want to put into a string, but we want to put
a calculation, so to speak, or in this case, a comparison.
So that whole expression, so to say, and then we need to use these curly brackets.
So we're saying, please run the code within the curly brackets and then print the result in the stead.
So at this spot of our code.
So now if we run this.
We can see that it says is five crater three is true.
Well, of course it's true because five is a greater number than three years.
But now let's say we check the same thing with a minus five.
If that is greater than three, then it should be false and that we are just false.
Of course, I didn't add the minus here in the print statement.
All right.
But get the gist of it now.
Of course, we can do the same with some other print statements here.
So print 11 is five, lower equal three.
And then please try to do the expression in here.
So try it yourself before I will show you how to.
All right, so the expression starts with a curly bracket and then we say five less than equal three.
All right, so this is the expression now let's see what we get as a result here and we can see is five
lower equal three it says false because five is a greater number than three.
So the whole expression.
Ends up being false, and that's what we get as the print statement here.
So this concept that we use here is called string interpolation.
All right.
So just so you have seen this keyword, of course, you can now go ahead and do the same with the other
comparison operators that we've seen there at the top.
So instead, we can use Krater equal and here is higher or greater equal three.
And then.
We saw the other one, right?
I actually.
Is.
Les.
Three.
And I let's to run this.
So now we have all of our results here.
Is not equal this false or is minus five?
Less than three, it's true, of course, because a negative value is going to be less than a positive
value than we have is lower or five lower equal three is false and is five greater equal.
Three is true.
Of course, we can also set a five in there just to see if this is still going to work.
And once we run it, we can see is five greater equal?
Five is also true because five is equal, five.
That's why this equation is correct.
So this greater equal is accepting both.
So it's going to return true if the left value is greater than the right value or if they are equal.
All right.
So that's it for assignment operators.
And the next video, we are going to check out increment and decrement operators.
So see their.