Now so far what we have seen are all operators that exist in normal mathematics.
But here are some that only exist in programming.
So take a look at this expression.
We create a variable called x and we set it equal to 5.
Then we change the value of x to the previous value, which is 5, plus 1.
So x now equals 6.
Now we've seen this and we've been using this in our previous code.
So this should be familiar to you already.
But in most programming languages, instead of writing out x = x + 1, you can simply write
x++, and, in exactly the same way, x now gets incremented by 1 and is now equal to 6. So x++
is the equivalent of saying x = x + 1, and this is called the increment expression.
Now you can go the other way as well.
You can write x--,
and this is equivalent to x = x - 1.
So the previous value of x, 5, minus 1, so x now equals 4.
And this is called the decrement expression.
Now you might have heard of the programming language C and C++, and this is kind of like a programmer's
idea of a good joke, even though nobody else thinks it's funny.
But essentially C++ was meant to be an increment on the C programming language.
So it's kind of like C plus one, a little bit better than C. Remember that with ++ and --,
you're only ever changing the value by one.
Now if you ever want to increase the value of x by more than one, then you can use the +=, and
this is equivalent to saying x = x + 2.
And so x now equals 7. In the same way,
you can also use += to increase by the value of another variable.
So in this case x = x + y, which is equal to 8.
And this also works with -=, *=, /=,
and it's a handy shorter way of doing exactly that.
So, in the next lesson,
I have a brief quiz for you to see if all of this stuck
and if it makes sense.
So head over there and see if you can complete the multiple choice question and I'll see you on the
next module.