Incrementation or
Decrementation
by ilyas usal
- increment by 1
First: what does increment mean? When I say that I increment a value by 1, it
only means that I add 1 to this value. There are several ways I can do that,
the obvious one being:
myValue = myValue + 1;
But there is a faster way: with the ++
operator. It will go like this:
myValue++;
It has the exact same effect, but it's faster and cleaner. You can do the
exact same with -, which is called decrementation:
myValue--;
- Increment by
another value
This time, I want to add a number to a value. The usual way would be:
myValue = myValue + 3;
Well, there's a much shorter way to do that:
myValue += 3;
It also works with the other operators:
myValue -= 3;
myValue *= 3;
myValue /= 3;
Hope this tutorial helped. If you have any
questions, please post them on the forums at
//www.kirupa.com/forum/
|