Function declaration

Kotlin is a fun programming language, and so the function name begins with the word fun. The fun statement is followed by the function name with parentheses ( ). The code block is defined after the parenthesis within the curly brackets as { code block }. Once we have finished writing our code block, we can call this function from anywhere by using nameOfTheFunction. Writing hello function displays a greeting message on the screen. See the following example:

fun hello(){
println("Hello from Kotlin")
}
fun main(args: Array<String>) {
hello()
}

A simple Hello from Kotlin message will now display on the screen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.220.83