DEV Community

UberGamz
UberGamz

Posted on

Kotlin Functions

Kotlin Functions
Kotlin functions are very easy if you understand all the pieces. Looking up instructions give some very complicated explanations. Without having experience or knowledge of the various pieces of code Kotlin has, it is nearly impossible to translate.
Starting as basic as it gets, here is an example.
fun add (n, i){return n+ i}
First we have the "fun" code. All lowercase and this never changes, it's required to signify to the compiler that the following pieces are a function.
"add" is the function name. This can be whatever you want it to be, but try to keep it appropriate so you can remember what it does.
(n, i) are each also made up. They are basically place holders for when you ask the function to be completed. If we sent a "1" and a "2" to the function, it would actually read (1,2). You separate your values, as many as you need, by a comma. 
{return n + i} is the actual operation. It will take the user input you have, and calculate.
Later you can add more to the code, like types or more inputs or even more calculations.
To send information to the function, you can call it up by the function name and a parenthesis around your input.
add(1,2)

Top comments (0)