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 = falseIn 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
BeginnerDeclare 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 = falseTry it yourself
// Type your code below
let boolean = ?
// Don't change the line below
print("boolean = \(boolean)")This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorCompound AssignmentRecap - Simple MathComparison Operators7Basic IO
Print FunctionString InterpolationReadLine InputType ConversionRecap - Till 120Recap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesArgument LabelsRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Sequences
Iterating Over ElementsThe Enumerated MethodIterating Over Strings P1Iterating Over Strings P22Variables
Let vs VarType AnnotationsNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting Input3Optionals
What Are OptionalsUnwrapping With If LetGuard LetNil Coalescing OperatorRecap - Safe Unwrapping9Loops
For-In LoopWhile LoopRepeat-While LoopBreakContinueRecap - FactorialRanges In LoopsNested LoopRecap - Dynamic Input