Define a helper function inside another function.

Local Functions

LocalFunctions.kt
fun main() {
    val bonus = 

    fun addBonus(points: Int): Int {
        return points + bonus
    }

    val base = 10
    val total = addBonus(base)

    println("bonus=$bonus")
    println("total=$total")
}
fun main() {
    val bonus = 

    fun addBonus(points: Int): Int {
        return points + bonus
    }

    val base = 10
    val total = addBonus(base)

    println("bonus=$bonus")
    println("total=$total")
}
fun main() {
    val bonus = 

    fun addBonus(points: Int): Int {
        return points + bonus
    }

    val base = 10
    val total = addBonus(base)

    println("bonus=$bonus")
    println("total=$total")
}
scope A local function is visible only inside the function that defines it.