Kotlin Tutorial 3 — Basic Operators
Kotlin provides the usual assortment of operators that you would expect to find in other programming languages, for which the tutorial covers the basic ones that are regularly used. Just like Python Kotlin allows operator overloading, but only for certain operators. Operator overloading is outside the scope of the tutorial series.
One of the first operators you have used in the tutorial series is the assignment operator (=) which needs no explanation.
Calculation Operators
For basic calculations Kotlin provides the (, ), /, *, +, –, and % operators. Try the following below in the Kotlin REPL:
Kotlin also the provides the *=, ++, — , and /= operators. Try the following below in the Kotlin REPL:
When determining the order of calculations Kotlin will use the BEDMAS system. Do note that Kotlin doesn’t have operators for shift left, and shift right.
Logic Operators
For basic logic operators Kotlin provides the !, >=, <=, ==, === and != operators. Try the following below in the Kotlin REPL:
Conclusion
You now have a basic understanding of doing calculations and logic using operators. Next tutorial will cover interaction with a program in Kotlin Tutorial 4 — Handling Input And Output.
TOC
- Kotlin Tutorial 1 — Introduction
- Kotlin Tutorial 2 — Basic Data Types
- Kotlin Tutorial 3 — Basic Operators
- Kotlin Tutorial 4 — Handling Input And Output
- Kotlin Tutorial 5 — Basic Collections
- Kotlin Tutorial 6 — Control Flow
- Kotlin Tutorial 7 — Functions
- Kotlin Tutorial 8 — Modularity
- Kotlin Tutorial 9 — Using An IDE
- Kotlin Tutorial 10 — Classes
- Kotlin Tutorial 11 — Inheritance
- Kotlin Tutorial 12 — Encapsulation And Polymorphism
- Kotlin Tutorial 13 — Generics