Boolean và Kiểu Bool trong Swift
1. Khai báo Bool
let isSwiftFun: Bool = true
let isPythonBetter: Bool = false
var isValid = true
var isEmpty = false2. Bool từ so sánh
let age = 25
let isAdult = age >= 18 // true
let score = 85
let isPassed = score >= 50 // true3. Logical Operators
let a = true
let b = false
print(a && b) // false - AND
print(a || b) // true - OR
print(!a) // false - NOT4. Bool trong conditions
let isWeekend = true
if isWeekend {
print("Day off!")
}
let status = isWeekend ? "Weekend" : "Weekday"📝 Tóm tắt
Bool-truehoặcfalse&&,||,!- Logical operators- Short-circuit evaluation
Last updated on
Swift