Skip to Content

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 = false

2. Bool từ so sánh

let age = 25 let isAdult = age >= 18 // true let score = 85 let isPassed = score >= 50 // true

3. Logical Operators

let a = true let b = false print(a && b) // false - AND print(a || b) // true - OR print(!a) // false - NOT

4. Bool trong conditions

let isWeekend = true if isWeekend { print("Day off!") } let status = isWeekend ? "Weekend" : "Weekday"

📝 Tóm tắt

  • Bool - true hoặc false
  • &&, ||, ! - Logical operators
  • Short-circuit evaluation
Last updated on