Menu
Coddy logo textTech

Boolean

Part of the Fundamentals section of Coddy's Swift journey — lesson 8 of 86.

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

Note that in Swift these values are lowercase, unlike some other languages.

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

let variableTrue = true
let variableFalse = false

In the above, two constants 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 constant named boolean and assign it the value true.

Cheat sheet

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

In Swift, Boolean values are lowercase:

let variableTrue = true
let variableFalse = false

Try it yourself

// Type your code below
let boolean = ?

// Don't change the line below
print("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