Browse topics
Kotlin Basics
Kotlin Functions
Define functions with default, named and vararg parameters, single-expression, local, tailrec and infix functions.
Kotlin FunctionsDefining Function and Its Type Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.Kotlin FunctionsSimple Function Example Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.Kotlin FunctionsParameterized Function Example Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.kotlin functionsDefault Parameters in KotlinFunction parameters can declare default values so callers may omit them. A Kotlin example with source code and sample output.kotlin functionsNamed Parameters in KotlinCallers can pass arguments by parameter name for clarity. A Kotlin example with source code and sample output.kotlin functionsVararg Parameters in KotlinA vararg parameter accepts zero or more values of the same type. A Kotlin example with source code and sample output.kotlin functionsSingle Expression Functions in KotlinWhen a function body is a single expression, you can use the = syntax. A Kotlin example with source code and sample output.kotlin functionsLocal Functions in KotlinA function declared inside another function is called a local function. A Kotlin example with source code and sample output.kotlin functionstailrec Functions in Kotlintailrec marks a recursive function that calls itself as the last operation. A Kotlin example with source code and sample output.kotlin functionsInfix Functions in KotlinAn infix function is called without dot notation between the receiver and argument. A Kotlin example with source code and sample output.
Related topics
Basic Programs Get started with Kotlin: your first program, variables, and comments. Kotlin Data Types Explore Int, Float, Double, Char, Boolean, String and more, with type conversion. Kotlin Operators Arithmetic, relational, logical, assignment and Kotlin's special operators. Conditional Statements Control program flow with if, when, break, continue and return. Kotlin Input and Output Read input and print output in Kotlin, including the Scanner class. Looping & Controls Repeat work with for, while, do-while and the repeat function.