2.3 Range | Logical Operators

Range Operators

Closed ...

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

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]<br>
for i in 0..<someArray.count {<br>
   print(someArray[i])<br>
}

Logical Operators

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