LoginSignup
6
3

More than 5 years have passed since last update.

[Swift]Bool型

Posted at

Bool

  • 真理値を表す
    • ある命題が真であるか偽であるか

真理値リテラル

  • 真理値を表すリテラル
    • true: 真
    • false: 偽
  • 真理値リテラルの代入先の型はBool

論理演算

  • 否定
  • 論理積
  • 論理和

Swiftの演算子の配置位置

  • 前置演算子
    • -a
  • 中置演算子
    • a + b
  • 後置演算子
    • a!

否定

  • 真理値の真偽を逆にする
  • 前置演算子 !
否定
let a = true    // true
let b = !a      // false

論理積

  • 与えられた複数の真理値がいずれも真であれば真
  • 中置演算子 &&
  • 両辺にBool型を取る
論理積
let a = false && false  // false
let b = false && true   // false
let c = true && false   // false
let d = true && true    // true

論理和

  • 与えられた複数の真理値の少なくともどれか1つが真であれば真
  • 中置演算子 ||
  • 両辺にBool型を取る
論理和
let a = false || false  // false
let b = false || true   // true
let c = true || false   // true
let d = true || true    // true
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3