Menu
Coddy logo textTech

Boolean

Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 9 of 93.

A Boolean type has only 2 possible values: true or false.

Note that in Kotlin these values are lowercase.

Here is an example of assigning a Boolean value to a variable:

fun main() {
    val variableTrue = true
    val variableFalse = false
}

In the above, two values named variableTrue and variableFalse are initialized, with the values true and false respectively.

Booleans are the building blocks for creating logic in the programs we write. We have a whole chapter about logic and conditions.

challenge icon

Challenge

Beginner

Declare a value named boolean and assign it the value true.

Try it yourself

fun main() {
    // Type your code below
    val boolean = ?

    // Don't change the line below
    println("boolean = $boolean")
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Kotlin playground