A variable can be assigned value multiple times.
Let's look at this example:
Output:
In this case num
has been assigned value multiple times.
Variables can be assigned values of other variables (line 14
).
Also a variable can receive a new value by using it's current value (line 15
).
They assign values and make the code shorter.
num += 2
is the same as num = num + 2
.
Example:
Output:
num -= 5
is the same as num = num - 5
.
Example:
Output:
num *= 7
is the same as num = num * 7
.
Example:
Output:
num /= 10
is the same as num = num / 10
.
Example:
Output: