Increment & Decrement

Reading Time: < 1 minuteIn this tutorial we will learn how works in kotlin the increment and decrement operator.
As in other programming languages, increment and decrement works in kotlin the same way.

Increment Operator (++) in Kotlin

The increment operator (++) provides a shortcut for adding 1 to a variable.

Decrement Operator () in Kotlin

Similarly, the decrement operator () is used to subtract 1 from the variable.

Prefix & Postfix

Both, increment and decrement operators have prefix (before the name of the variable) and postfix (after the name of the variable) forms.

The prefix form increments the variable and then uses it
in the assignment statement.

The same applies to the decrement operator.

The postfix form uses the value of the variable first, before incrementing it.

The same applies to the decrement operator.

Questions

I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉

Have a nice a day! 🙂

 


 

Follow and like us:

Click to rate this post!
[Total: 0 Average: 0]

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications