Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,680 --> 00:00:06,800
Now so far what we have seen are all operators that exist in normal mathematics.
1
2
00:00:07,020 --> 00:00:10,970
But here are some that only exist in programming.
2
3
00:00:11,310 --> 00:00:14,050
So take a look at this expression.
3
4
00:00:14,070 --> 00:00:17,590
We create a variable called x and we set it equal to 5.
4
5
00:00:17,700 --> 00:00:23,760
Then we change the value of x to the previous value,
which is 5, plus 1.
5
6
00:00:23,880 --> 00:00:26,070
So x now equals 6.
6
7
00:00:26,070 --> 00:00:29,790
Now we've seen this and we've been using this in our previous code.
7
8
00:00:29,850 --> 00:00:31,870
So this should be familiar to you already.
8
9
00:00:31,920 --> 00:00:39,360
But in most programming languages, instead of writing out x = x + 1, you can simply write
9
10
00:00:39,420 --> 00:00:49,260
x++, and, in exactly the same way, x now gets incremented by 1 and is now equal to 6. So x++
10
11
00:00:49,650 --> 00:00:56,760
is the equivalent of saying x = x + 1, and this is called the increment expression.
11
12
00:00:56,760 --> 00:00:58,740
Now you can go the other way as well.
12
13
00:00:58,740 --> 00:01:00,950
You can write x--,
13
14
00:01:01,080 --> 00:01:05,250
and this is equivalent to x = x - 1.
14
15
00:01:05,280 --> 00:01:10,650
So the previous value of x, 5, minus 1, so x now equals 4.
15
16
00:01:10,920 --> 00:01:13,440
And this is called the decrement expression.
16
17
00:01:13,440 --> 00:01:20,670
Now you might have heard of the programming language C and C++, and this is kind of like a programmer's
17
18
00:01:20,670 --> 00:01:24,720
idea of a good joke, even though nobody else thinks it's funny.
18
19
00:01:24,750 --> 00:01:31,100
But essentially C++ was meant to be an increment on the C programming language.
19
20
00:01:31,110 --> 00:01:37,920
So it's kind of like C plus one, a little bit better than C. Remember that with ++ and --,
20
21
00:01:38,040 --> 00:01:40,890
you're only ever changing the value by one.
21
22
00:01:40,890 --> 00:01:47,790
Now if you ever want to increase the value of x by more than one, then you can use the +=, and
22
23
00:01:47,800 --> 00:01:52,280
this is equivalent to saying x = x + 2.
23
24
00:01:52,350 --> 00:01:55,400
And so x now equals 7. In the same way,
24
25
00:01:55,410 --> 00:02:00,530
you can also use += to increase by the value of another variable.
25
26
00:02:00,540 --> 00:02:05,370
So in this case x = x + y, which is equal to 8.
26
27
00:02:05,370 --> 00:02:10,270
And this also works with -=, *=, /=,
27
28
00:02:10,410 --> 00:02:13,850
and it's a handy shorter way of doing exactly that.
28
29
00:02:13,860 --> 00:02:15,660
So, in the next lesson,
29
30
00:02:15,690 --> 00:02:19,620
I have a brief quiz for you to see if all of this stuck
30
31
00:02:19,740 --> 00:02:21,390
and if it makes sense.
31
32
00:02:21,480 --> 00:02:27,300
So head over there and see if you can complete the multiple choice question and I'll see you on the
32
33
00:02:27,300 --> 00:02:28,190
next module.
3236
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.