1 00:00:00,570 --> 00:00:01,440 Welcome back. 2 00:00:01,730 --> 00:00:08,550 And this video, we're going to look at another type of operators, the comparison operators, so comparison 3 00:00:08,550 --> 00:00:10,940 operators are the ones that you can see here. 4 00:00:10,950 --> 00:00:17,250 So double equal, not equal less than greater than less than equal or greater equal. 5 00:00:17,490 --> 00:00:21,000 So now let's see how they are used in Scotland. 6 00:00:21,600 --> 00:00:31,020 First of all, let's create this variable called is equal, and it's going to be the result of the following 7 00:00:31,890 --> 00:00:35,610 operation, which means five, equal equal three. 8 00:00:36,180 --> 00:00:37,860 So what does that do? 9 00:00:38,160 --> 00:00:45,210 Well, it checks if the value on the left hand side is the same as the value on the right hand side. 10 00:00:45,480 --> 00:00:48,270 So that's what this double equal sign does. 11 00:00:48,600 --> 00:00:55,210 So it's comparing two values to each other, and it's going to give us a Boolean result. 12 00:00:55,290 --> 00:01:00,300 So it says it's a Boolean expression, even though we can simplify the Boolean expression. 13 00:01:00,300 --> 00:01:01,170 So let's just do that. 14 00:01:01,590 --> 00:01:04,890 You can say it gives me the result directly, which is false. 15 00:01:05,099 --> 00:01:10,590 But of course, that's not what I wanted because what I wanted is to display this operation here, which 16 00:01:10,590 --> 00:01:18,540 is just saying, OK, one side equal, equal the other side, or is the one side the same value as the 17 00:01:18,540 --> 00:01:21,720 other side of this equation here? 18 00:01:22,050 --> 00:01:27,090 So if you do that, you will get a result, which is either false or true. 19 00:01:27,270 --> 00:01:31,740 So if we do the same with five equals equals five, then of course the result will be true. 20 00:01:32,130 --> 00:01:35,970 And in this case, it's super obvious because we can see those values. 21 00:01:36,180 --> 00:01:42,240 But let's say they are hidden behind a variable where you can't always see the variable value, then 22 00:01:42,240 --> 00:01:49,530 this will be a very useful operation because maybe you even want to do something based on that operation. 23 00:01:50,070 --> 00:01:55,470 So let's say if this condition is true, then you want to run some code, then it's going to be very 24 00:01:55,470 --> 00:01:58,680 important to do this type of comparison operations. 25 00:01:58,950 --> 00:02:03,390 And of course, this is also something that we are going to look at later on, which are if statements. 26 00:02:03,660 --> 00:02:08,160 But for now, this is our very simple operation that we have here. 27 00:02:08,550 --> 00:02:18,300 So now let's go ahead and print something onto our console and I'm going to write is equal is plus is 28 00:02:18,570 --> 00:02:19,050 equal. 29 00:02:19,560 --> 00:02:23,550 So what I'm doing here is using concatenation. 30 00:02:24,420 --> 00:02:25,530 So it's just. 31 00:02:26,940 --> 00:02:32,220 Using this drink and then it's converting this into his drink and just saying whatever the value is. 32 00:02:32,640 --> 00:02:36,630 So if we run that we can see that is equal is false. 33 00:02:37,140 --> 00:02:39,240 So our is equal is false. 34 00:02:39,570 --> 00:02:46,890 So then of course, our I.D., which means our Android Studio says, hey, you can convert concatenation 35 00:02:46,890 --> 00:02:47,640 to a template. 36 00:02:47,670 --> 00:02:48,450 So let's do that. 37 00:02:48,600 --> 00:02:50,100 And you can see what it does. 38 00:02:50,490 --> 00:02:55,710 It changes this to having a very different way of writing it. 39 00:02:56,100 --> 00:03:01,850 So one was the concatenation, and this one is a template that we're using here, which requires this 40 00:03:01,860 --> 00:03:02,640 dollar sign. 41 00:03:03,090 --> 00:03:10,350 So what we can do is we can use this dollar sign and afterwards, whatever the value or the variable 42 00:03:10,350 --> 00:03:13,590 that we want to use is will be printed here. 43 00:03:14,130 --> 00:03:17,780 So in this case, it's just going to be the result of whatever we had here. 44 00:03:17,790 --> 00:03:20,310 So if we run, this will result in the same. 45 00:03:21,550 --> 00:03:27,580 Type of print statement that we have here, and so I need to run it twice and we are is equal is false. 46 00:03:28,480 --> 00:03:35,950 So now let's use this a little more because let's create a another comparison where I'm just going to 47 00:03:35,950 --> 00:03:41,560 create is not equal is going to be five, not equal five. 48 00:03:41,710 --> 00:03:45,020 So let's just test if that is true or false. 49 00:03:45,040 --> 00:03:48,250 Of course, it's going to be false because five is equal. 50 00:03:48,250 --> 00:03:48,640 Five. 51 00:03:49,390 --> 00:03:56,710 But if we just print that now and let me put it this again, but now with is not equal. 52 00:03:57,580 --> 00:03:57,920 All right. 53 00:03:57,920 --> 00:04:01,450 So now I'm using is not equal instead of is equal. 54 00:04:01,720 --> 00:04:08,110 And to comment this line out and I'm going to change the name here as well. 55 00:04:08,110 --> 00:04:10,840 So it's going to be is not equal is. 56 00:04:11,050 --> 00:04:14,860 And then let's see if it's true or false and we can see it says is not equal. 57 00:04:14,860 --> 00:04:17,490 It is false because five is equal five. 58 00:04:17,500 --> 00:04:19,930 But we are checking if five is not equal. 59 00:04:19,930 --> 00:04:20,209 Five. 60 00:04:20,230 --> 00:04:25,210 So this exclamation mark here says that it should be not equal. 61 00:04:25,390 --> 00:04:30,310 So this year is another way of testing a comparison. 62 00:04:30,700 --> 00:04:33,430 But of course, there are a bunch more that we have here. 63 00:04:33,730 --> 00:04:37,720 So what we can check is, let's say, the following. 64 00:04:37,810 --> 00:04:43,450 So instead of creating a new variable for every single one of those comparison operators, let's just 65 00:04:43,450 --> 00:04:45,550 do it in the print line statement directly. 66 00:04:45,880 --> 00:04:46,330 So. 67 00:04:47,710 --> 00:04:52,120 Is greater, so in this case is five greater. 68 00:04:52,450 --> 00:04:54,970 Three is going to be. 69 00:04:56,260 --> 00:05:03,700 And now I'm using something very cool here because I'm using another pretty cool feature here of Scotland 70 00:05:03,970 --> 00:05:07,180 where we have the same principle that we had here. 71 00:05:07,390 --> 00:05:14,350 But now, because we don't just have one variable that we want to put into a string, but we want to 72 00:05:14,350 --> 00:05:19,030 put a calculation, so to speak, or in this case, a comparison. 73 00:05:19,480 --> 00:05:21,640 So the whole expression, so to say. 74 00:05:21,850 --> 00:05:24,640 And then we need to use these curly brackets. 75 00:05:24,700 --> 00:05:31,360 So we're saying, please run the code within the curly brackets and then print the result in this stead. 76 00:05:31,540 --> 00:05:33,730 So at this spot of our code? 77 00:05:34,480 --> 00:05:35,890 So now if we run this. 78 00:05:37,680 --> 00:05:42,060 We can see that it says is five greater, three is true. 79 00:05:42,210 --> 00:05:46,050 Well, of course it's true because five is a greater number than three years. 80 00:05:46,800 --> 00:05:50,160 But now let's say we check the same thing with a minus five. 81 00:05:50,730 --> 00:05:54,030 If that is greater than three, then it should be false. 82 00:05:54,630 --> 00:05:55,300 And then we are. 83 00:05:55,300 --> 00:05:55,950 It's as false. 84 00:05:56,070 --> 00:05:59,280 Of course, I didn't add the minus here in the print statement. 85 00:05:59,730 --> 00:06:01,140 All right, but get the gist of it. 86 00:06:01,710 --> 00:06:06,060 Now, of course, we can do the same with some other print statements here. 87 00:06:06,070 --> 00:06:18,090 So print alone is five lower equal three, and then please try to do the expression in here. 88 00:06:18,420 --> 00:06:20,910 So try it yourself before I will show you how to. 89 00:06:22,380 --> 00:06:22,810 All right. 90 00:06:22,830 --> 00:06:30,660 So the expression starts with a curly bracket, and then we say five less bun equals three. 91 00:06:31,870 --> 00:06:33,280 All right, so this is the expression. 92 00:06:33,670 --> 00:06:39,550 Now let's see what we get as a result here, and we can see his five lower equal three. 93 00:06:39,640 --> 00:06:43,480 It says false because five is a greater number two and three. 94 00:06:43,720 --> 00:06:45,550 So the whole expression. 95 00:06:46,510 --> 00:06:48,050 Ends up being false. 96 00:06:48,070 --> 00:06:51,160 And that's what we get as the print statement here. 97 00:06:51,790 --> 00:06:56,590 So this concept that we use here is called string interpolation. 98 00:06:56,890 --> 00:06:57,250 All right. 99 00:06:57,250 --> 00:07:01,180 So just so you have seen this keyword. 100 00:07:01,990 --> 00:07:07,600 Of course, you can now go ahead and do the same with the other comparison operators that we've seen 101 00:07:07,600 --> 00:07:08,590 there at the top. 102 00:07:08,620 --> 00:07:19,360 So instead, we could use greater equal and here is higher or greater equal. 103 00:07:19,660 --> 00:07:20,110 Three. 104 00:07:20,770 --> 00:07:21,520 And then. 105 00:07:22,740 --> 00:07:23,930 We saw the other one, right? 106 00:07:24,450 --> 00:07:25,110 I actually. 107 00:07:27,450 --> 00:07:27,960 Is. 108 00:07:28,950 --> 00:07:29,520 Less. 109 00:07:30,560 --> 00:07:31,010 Three. 110 00:07:32,590 --> 00:07:33,640 And let's run this. 111 00:07:35,400 --> 00:07:38,610 So now we have all of our results here. 112 00:07:40,700 --> 00:07:46,310 Is not equal, this falls here is five minus five less than three, it's true, yeah, of course, because 113 00:07:46,670 --> 00:07:53,930 a negative value is going to be less than a positive value than we have is lower or five lower. 114 00:07:53,930 --> 00:07:57,080 Equal three is false and is five greater equal. 115 00:07:57,080 --> 00:07:58,070 Three is true. 116 00:07:58,740 --> 00:08:04,550 Of course, we can also set a five in there just to see if this is still going to work. 117 00:08:06,220 --> 00:08:13,300 And once we run it, we can see is five greater equal, five is also true because five is equal five. 118 00:08:13,360 --> 00:08:15,460 That's why this equation is correct. 119 00:08:15,730 --> 00:08:19,840 So there's greater equal is accepting both. 120 00:08:20,080 --> 00:08:26,140 So it's going to return true if the left value is greater than the right value or if they are equal. 121 00:08:26,920 --> 00:08:27,220 All right. 122 00:08:27,220 --> 00:08:29,110 So that's it for assignment operators. 123 00:08:29,350 --> 00:08:33,830 And the next video, we are going to check out increment and decrement operators. 124 00:08:33,880 --> 00:08:34,659 So see you there.