[Grammer] 16 - Overflow Operators, 17 - Comparison Operators, 18 - Logical Operators

in swift4 •  6 years ago 
  • Overflow Operatiors
    &+ : Overflow Addition Operator
    &- : Overflow Subtraction Operator
    &*: Overflow Multiplication Operator
let a: Int8 = Int8.max

let result = a &+ 1 // -128

let b: Int8 = Int8.min

let result2 = a &- 1 // 127
  • Comparison Operators : ==, !=, >, <, >=, <=
    항상 이항연산자로 사용되고, 반환값은 Bool 타입이다.
let a = 0
let b = 1
let c = 1
a == b // false
b != c // false
a > b // false
b > c // false
b >= c // true
  • Logical Operators : 모든 논리연산의 반환값은 Bool 타입이다.
    &&(Logical AND Operator) : 둘 중 하나라도 false이면 false, 아니면 true
    ||(Logical OR Operator) : 둘 중 하나라도 true이면 true, 아니면 false
    !(Logical NOT Operator) : true -> false, false -> true
let num = 11
if num > 10 && num % 2 == 0 {
   print(true)
} else {
   print(false)
}
// false
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!