Skip to content

Instantly share code, notes, and snippets.

@Ayeeta
Created August 1, 2020 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayeeta/429efba091e34aae7ca38341c83a3c83 to your computer and use it in GitHub Desktop.
Save Ayeeta/429efba091e34aae7ca38341c83a3c83 to your computer and use it in GitHub Desktop.
Functions in Kotlin
//Example with no args
fun exampleFunction(){
println("This is an example of a function in Kotlin")
}
//Example with Args. Remember the data types are declared explicitly
fun exampleFunctionWithArgs(someString:String){
println(someString)
}
/**
Example with return type
**/
fun calculateArea(l:Int, w:Int):Int{
val result = l * w
return result
}
//You can also assign your args like this
fun randomFun(msg: String = "This is so random"){
println(msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment