1 00:00:00,510 --> 00:00:01,260 Welcome back. 2 00:00:01,530 --> 00:00:09,060 And this video, we are going to check out the assignment operators and the increment or decrement operators 3 00:00:09,060 --> 00:00:10,710 because we're going to use them quite a bit. 4 00:00:11,010 --> 00:00:16,410 So assignment operators are the ones you can see here, and we have already seen them to a certain degree 5 00:00:16,680 --> 00:00:18,400 where we just had a variable. 6 00:00:18,690 --> 00:00:20,100 And I'm just going to call this one. 7 00:00:20,110 --> 00:00:27,510 My name is going to be five and then I can go ahead and say my name plus equal three. 8 00:00:27,750 --> 00:00:32,520 So what that will do is it will add three to my mum value. 9 00:00:32,520 --> 00:00:40,440 So it's going to be the same thing as if I wrote My name equals my num plus three. 10 00:00:41,130 --> 00:00:41,430 All right. 11 00:00:41,430 --> 00:00:43,170 So these two are interchangeable. 12 00:00:43,440 --> 00:00:47,610 And as you can see, it even prefers the other one. 13 00:00:47,610 --> 00:00:52,800 So it even prefers the operator assignment, as we have seen here. 14 00:00:53,370 --> 00:00:54,150 All right, so. 15 00:00:54,330 --> 00:01:01,650 Assignment operator is this plus equal three or this minus equal or multiplied equal and so forth? 16 00:01:02,070 --> 00:01:10,560 So I can, of course, go ahead and print this print and it's going to be my name is Taylor my name, 17 00:01:11,520 --> 00:01:19,260 and I'm going to comment on all our other print line statements from earlier videos. 18 00:01:19,260 --> 00:01:20,190 And let's run this again. 19 00:01:22,310 --> 00:01:25,280 And as we see says, my name is eight. 20 00:01:26,000 --> 00:01:29,000 All right, so that is an assignment operator. 21 00:01:29,000 --> 00:01:35,990 Now please go ahead and multiply that with four, so multiply my number with four and stored it in my 22 00:01:35,990 --> 00:01:38,270 name, but use an assignment operator for this. 23 00:01:40,840 --> 00:01:48,670 All right, I hope you tried it, so it's my numb multiplication or asterisk equal four. 24 00:01:49,210 --> 00:01:51,490 And now let's print this again. 25 00:01:53,560 --> 00:01:54,400 In the next line. 26 00:01:55,940 --> 00:01:57,860 And we can see it's 32. 27 00:01:58,610 --> 00:02:00,920 All right, so these are the assignment operators. 28 00:02:01,220 --> 00:02:07,670 Now let's look at the increment and decrement operators because they are something that is used quite 29 00:02:07,700 --> 00:02:12,530 often as well, and they are just a double plus or double minus sign. 30 00:02:12,980 --> 00:02:20,030 So we can just go ahead and do the following my num plus plus nothing more than that. 31 00:02:20,600 --> 00:02:22,970 So let's print my name again. 32 00:02:25,200 --> 00:02:32,100 And this is going to be here, actually, let's print it here, and let's print it after the incrementing. 33 00:02:32,460 --> 00:02:39,450 So this plus plus is incrementing, which means increasing the value by one and then minus minus decremental, 34 00:02:39,570 --> 00:02:43,500 which means decreasing the value by one or reducing one. 35 00:02:45,330 --> 00:02:51,810 So once we run this, we can see my name is 32 and my name is 33, so my name is 32 here at this line 36 00:02:52,140 --> 00:02:54,240 and 33 and this line. 37 00:02:54,840 --> 00:02:56,410 So that's what this increment does. 38 00:02:56,430 --> 00:02:58,820 Now let's do a decrement. 39 00:02:58,830 --> 00:03:07,080 And at that same time, I want to show you something that is super interesting and that is to use to 40 00:03:07,080 --> 00:03:12,240 increment after use, which means we use increment after my name. 41 00:03:13,110 --> 00:03:16,260 And then again, we can use it before. 42 00:03:17,650 --> 00:03:23,440 So in this case, you can see we cannot just use this approach, we have to use the brackets, so I'm 43 00:03:23,440 --> 00:03:31,030 going to use curly brackets here as well because this is an expression that I want to execute before 44 00:03:31,360 --> 00:03:33,220 actually printing it on the screen. 45 00:03:33,370 --> 00:03:38,620 So let me show you how this will impact our application here. 46 00:03:40,450 --> 00:03:42,130 So let's run this again. 47 00:03:44,370 --> 00:03:45,420 All right, so there we are. 48 00:03:45,810 --> 00:03:47,550 So we had minus 33. 49 00:03:47,820 --> 00:03:49,200 That's this line here, right? 50 00:03:49,380 --> 00:03:54,630 So we increased my name of being 32, which was at this point. 51 00:03:55,470 --> 00:03:58,020 And then we increased it by one here. 52 00:03:58,500 --> 00:04:05,730 Then we go ahead and print that number and then we say, OK, let's increase the value by one. 53 00:04:06,540 --> 00:04:08,790 But for some reason, it didn't increase the value. 54 00:04:08,820 --> 00:04:09,480 Why is that? 55 00:04:09,960 --> 00:04:18,930 Well, that is because this plus plus will only be executed once this line of code is finished, so 56 00:04:18,930 --> 00:04:20,970 pretty much at the beginning of the next line. 57 00:04:20,970 --> 00:04:25,770 So in line 75, my name is still 33. 58 00:04:26,370 --> 00:04:27,990 Then it's increased by one. 59 00:04:27,990 --> 00:04:32,940 So in line 76 at the beginning of the line, it's going to be 34. 60 00:04:33,480 --> 00:04:35,010 And then would you? 61 00:04:35,400 --> 00:04:43,200 Plus plus minus, which means we increment just before we execute or we use this variable, which means 62 00:04:43,200 --> 00:04:48,060 that now it was 34 at this point, +1, which means now it's 35. 63 00:04:48,450 --> 00:04:51,480 And that's exactly what is printed onto the console. 64 00:04:51,490 --> 00:04:55,440 So now you can see that my name is 35. 65 00:04:55,860 --> 00:05:01,470 So that's the difference between using the plus plus or the increment or decrement operators before 66 00:05:01,470 --> 00:05:06,660 or after, because it really has an impact on when they are executed. 67 00:05:06,660 --> 00:05:12,120 And now you know the difference, but very commonly it's used afterwards. 68 00:05:12,120 --> 00:05:17,910 So you increment after words because usually you don't use it in line as we do it here. 69 00:05:19,870 --> 00:05:23,410 So now please add another print line statement just underneath it. 70 00:05:23,650 --> 00:05:30,940 So in line 77, in my case, just underneath this statement and there decreased the value so that it 71 00:05:30,940 --> 00:05:37,510 will show my name is 34 as the next print line statement. 72 00:05:39,540 --> 00:05:39,930 All right. 73 00:05:40,080 --> 00:05:41,130 So I hope you tried it. 74 00:05:42,120 --> 00:05:47,670 So what I need here, of course, is to use minus minus before my name and not after one. 75 00:05:47,880 --> 00:05:56,880 So I'm going to decrement the mine unbearable just before it is going to be displayed and printed onto 76 00:05:56,880 --> 00:05:57,480 the console. 77 00:05:58,200 --> 00:06:00,270 So just before it will be used, so to say. 78 00:06:01,230 --> 00:06:02,220 So there we are. 79 00:06:02,280 --> 00:06:04,560 It says my name is 34. 80 00:06:05,540 --> 00:06:10,490 All right, so that's assignment operators and the increment and decrement operators. 81 00:06:10,880 --> 00:06:17,990 And in the next video, we are going to see how we can finally use some of those operations usefully 82 00:06:18,470 --> 00:06:23,210 because so far we had some examples of what we can do with it. 83 00:06:23,210 --> 00:06:28,910 But now let's see what we actually can do with it and get something from it, because so far that's 84 00:06:28,910 --> 00:06:31,790 been rather fundamental or rather basic. 85 00:06:31,790 --> 00:06:35,480 So see you in the next video where we're going to check out if statements.