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
BeginnerDeclare 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")
}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 OperatorAugmented AssignmentComparison OperatorsRecap - Simple Math7Basic IO
Println FunctionString TemplatesReadLine InputType ConversionRecap - Years Until RetirementRecap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesNamed ArgumentsDefault ValuesSingle Expression FunctionsRecap - Sigma FunctionRecap - Validation Function2Variables
Val vs VarType InferenceNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Logical Operators Part 3Ternary With If ExpressionRecap - Simple Logic8Bill Split Calculator
Welcome MessageGetting Input3Nullability
What Is Null SafetyNullable TypesSafe Call OperatorElvis OperatorFunction Challenge BasicsNot Null AssertionRecap - Safe Access6Decision Making
If StatementIf - ElseIf As An ExpressionWhen ExpressionWhen With RangesRecap - Simple Calculator9Loops
For LoopWhile LoopDo-While LoopBreakContinueRanges In LoopsNested LoopRecap - FactorialRecap - Dynamic InputPractice on your own: Kotlin playground