Welcome back.
And this video, we're 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 Scotland.
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 using concatenation.
So it's just.
Using this drink and then it's converting this into his drink 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 I.D., 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, and 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 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 it says is not equal.
It 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 in 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 Scotland
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 the 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 this stead.
So at this spot of our code?
So now if we run this.
We can see that it says is five greater, 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 then we are.
It's as 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 alone 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 bun equals three.
All right, so this is the expression.
Now let's see what we get as a result here, and we can see his five lower equal three.
It says false because five is a greater number two and 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 could use greater equal and here is higher or greater equal.
Three.
And then.
We saw the other one, right?
I actually.
Is.
Less.
Three.
And let's run this.
So now we have all of our results here.
Is not equal, this falls here is five minus five less than three, it's true, yeah, 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 there's 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 you there.