2.3 Range | Logical Operators

Range Operators

Closed ...

  • specify the beginning / end of the range (low left → high right)
for hello in 1...5 {
   print("\(hello)")
}

Half-open ..<

  • 0 ..< 10 → goes from 0 to 9
  • useful for arrays/dictionaries when you want to start at 0
let someArray = [8,4,3]
for i in 0..<someArray.count {
   print(someArray[i])
}

Logical Operators

!x        Logical NOT
x && y    Logical AND
x || y    Logical OR
  • used with Boolean values/expressions that return Bool values
let k = true, m = false

// -> false
let o = k && m
// -> true
let p = k || m