This course is currently a work in progress. Please join the waitlist to receive regular updates.
Increment or Decrement numbers in apex
In Apex, you can use the ++
or --
operators to increase or decrease a variable's value by one. The position of the operator (before or after the variable) determines when the value is updated during execution.
The following code snippet shows how to increment a variable value before and after it is used.
Loading...
In the above example:
- The variables count, currentCount, items, newItems are
Integer
variables. - The operator
++
on count variable, increment the value of count by onebefore
it is assgined to currentCount. - The operator
++
on items variable, increment the value of count by oneafter
it is assgined to newItems.
Try It Yourself
Loading...