August 2017
Intermediate to advanced
440 pages
10h
English
There are two kinds of increment (++ ) and decrements (--) operator: pre-increment/pre-decrement, where the operator is defined before the expression, and post-increment/post-decrement, where the operator is defined after the expression:
++speed //pre increment --speed //pre decrement speed++ //post increment speed-- //post decrement
In the preceding example, using post- instead of pre-increment/decrement would change nothing because those operations are executed in sequence. But this makes a huge difference when the increment/decrement operator is combined with a function call.
In the pre-increment operator, speed is retrieved, incremented, and passed to a function as an argument:
var speed = 1.0 println(++speed) ...
Read now
Unlock full access