Boolean Type and Values
Свайпніть щоб показати меню
Declaring Boolean Variables
In Kotlin, you declare a Boolean variable using the Boolean type. Boolean variables can hold one of two values: true or false.
Syntax for Declaration
Use the val keyword for a read-only (immutable) variable, or var for a mutable variable:
val isActive: Boolean = true
var isEnabled: Boolean = false
val isActive: Boolean = true;declares an immutable Boolean variable namedisActiveand sets its value totrue;var isEnabled: Boolean = false;declares a mutable Boolean variable namedisEnabledand sets its value tofalse.
You can also let Kotlin infer the type:
val isVisible = true
var isComplete = false
- Here,
isVisibleandisCompleteare both Boolean variables, with their types inferred based on the assigned values.
Boolean variables are essential for controlling program flow, as they are used in conditions and logical expressions.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 1
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Секція 1. Розділ 1